机器学习程序员Java 杂谈

机器学习实战(二) - 单变量线性回归

2018-12-14  本文已影响10人  紫霞等了至尊宝五百年

Model and Cost Function

1 模型概述 - Model Representation

To establish notation for future use, we’ll use

A pair (x(i),y(i)) is called a training example
the dataset that we’ll be using to learn—a list of m training examples (x(i),y(i));i=1,...,m—is called a training set.
the superscript “(i)” in the notation is simply an index into the training set, and has nothing to do with exponentiation

In this example

X = Y = R


To describe the supervised learning problem slightly more formally, our goal is,
given a training set, to learn afunction h : X → Yso that h(x) is a “good” predictor for the corresponding value of y.
For historical reasons, this function h is called a hypothesis. Seen pictorially, the process is therefore like this

2 代价函数 - Cost Function

代价函数是用来测量实际值和预测值精确度的一个函数模型.
We can measure the accuracy of our hypothesis function by using acost function.
This takes an average difference (actually a fancier version of an average) of all the results of the hypothesis with inputs from x's and the actual output y's.


首先需要搞清楚假设函数和代价函数的区别
当假设函数为线性时,即线性回归方程,其由两个参数组成:theta0和theta1




我们要做的就是选取两个参数的值,使其代价函数的值达到最小化



J(θ0,θ1)=12m∑i=1m(y^i−yi)2=12m∑i=1m(hθ(xi)−yi)2

To break it apart, it is 1/2 x ̄ where x ̄ is the mean of the squares of hθ(xi)−yi , or the difference
between the predicted value and the actual value.
This function is otherwise called theSquared error function, or Mean squared error.
The mean is halved (1/2)as a convenience for the computation of the gradient descent, as the derivative term of the square function will cancel out the 1/2 term.
The following image summarizes what the cost function does:



3 代价函数(一)

上一篇 下一篇

猜你喜欢

热点阅读