Model and Cost Function

Model and Cost Function


机器学习英文笔记,顺便学英语。(才发现视频后面的阅读就是笔记)


Model Representation

To establish notation for future use, we’ll use x(i) to denote the “input” variables (living area in this example), also called input features, and y(i) to denote the “output” or target variable that we are trying to predict (price). A pair (x(i),y(i)) is called a training example, and 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(训练集). Note that the superscript “(i)” in the notation is simply an index into the training set, and has nothing to do with exponentiation. We will also use X to denote the space of input values, and Y to denote the space of output values. In this example, X = Y = ℝ.

To describe the supervised learning problem slightly more formally, our goal is, given a training set, to learn a function h : X → Y so 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:

在这里插入图片描述
在这里插入图片描述
When the target variable that we’re trying to predict is continuous, such as in our housing example, we call the learning problem a regression problem. When y can take on only a small number of discrete values (such as if, given the living area, we wanted to predict if a dwelling is a house or an apartment, say), we call it a classification problem.
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

Cost Function

We can measure the accuracy of our hypothesis function by using a cost 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.

J ( θ 0 , θ 1 ) J(\theta_0, \theta_1) J(θ0,θ1) = 1 2 m ∑ i = 1 m ( y ^ i − y i ) 2 = 1 2 m ∑ i = 1 m ( h θ ( x i ) − y i ) 2 \dfrac {1}{2m} \displaystyle \sum _{i=1}^m \left ( \hat{y}_{i}- y_{i} \right)^2 = \dfrac {1}{2m} \displaystyle \sum _{i=1}^m \left (h_\theta (x_{i}) - y_{i} \right)^2 2m1i=1m(y^iyi)2=2m1i=1m(hθ(xi)yi)2

To break it apart, it is 1 2 x ˉ \frac{1}{2} \bar{x} 21xˉ where x ˉ \bar{x} xˉ is the mean of the squares of h θ ( x i ) − y i h_\theta (x_{i}) - y_{i} hθ(xi)yi , or the difference between the predicted value and the actual value.

This function is otherwise called the “Squared error function”, or “Mean squared error”. The mean is halved ( 1 2 ) \left(\frac{1}{2}\right) (21) as a convenience for the computation of the gradient descent, as the derivative term of the square function will cancel out the 1 2 \frac{1}{2} 21 term. The following image summarizes what the cost function does:
在这里插入图片描述

problem formulation
在这里插入图片描述

Cost Function - Intuition I

If we try to think of it in visual terms, our training data set is scattered on the x-y plane. We are trying to make a straight line (defined by h θ ( x ) h_\theta(x) hθ(x)) which passes through these scattered data points.

Our objective is to get the best possible line. The best possible line will be such so that the average squared vertical distances of the scattered points from the line will be the least. Ideally, the line should pass through all the points of our training data set. In such a case, the value of J ( θ 0 , θ 1 ) J(\theta_0, \theta_1) J(θ0,θ1) will be 0. The following example shows the ideal situation where we have a cost function of 0.
在这里插入图片描述
When θ 1 \theta_1 θ1 = 1, we get a slope of 1 which goes through every single data point in our model. Conversely, when θ 1 \theta_1 θ1 = 0.5, we see the vertical distance from our fit to the data points increase.
在这里插入图片描述
This increases our cost function to 0.58. Plotting several other points yields to the following graph:
在这里插入图片描述
Thus as a goal, we should try to minimize the cost function. In this case, θ 1 \theta_1 θ1 = 1 is our global minimum.

Cost Function - Intuition II

A contour plot(等高线图) is a graph that contains many contour lines. A contour line of a two variable function has a constant value at all points of the same line. An example of such a graph is the one to the right below.
在这里插入图片描述
Taking any color and going along the ‘circle’, one would expect to get the same value of the cost function. For example, the three green points found on the green line above have the same value for J ( θ 0 , θ 1 ) J(\theta_0,\theta_1) J(θ0,θ1) and as a result, they are found along the same line. The circled x displays the value of the cost function for the graph on the left when θ 0 \theta_0 θ0 = 800 and θ 1 \theta_1 θ1 = -0.15. Taking another h(x) and plotting its contour plot, one gets the following graphs:
在这里插入图片描述
When θ 0 \theta_0 θ0 = 360 and θ 1 \theta_1 θ1 = 0, the value of J ( θ 0 , θ 1 ) J(\theta_0,\theta_1) J(θ0,θ1) in the contour plot gets closer to the center thus reducing the cost function error. Now giving our hypothesis function a slightly positive slope results in a better fit of the data.
在这里插入图片描述
The graph above minimizes the cost function as much as possible and consequently, the result of θ 1 \theta_1 θ1 and θ 0 \theta_0 θ0 tend to be around 0.12 and 250 respectively. Plotting those values on our graph to the right seems to put our point in the center of the inner most ‘circle’.

words and phrases

English中文English中文
establish建立notation符号
denote表示slightly些微地
represent代表hypothesis假设
computation计算gradient梯度
descent下降derivative派生物;导数
cancel out取消;抵消scattered分散的
vertical垂直Ideally理想地
Conversely相反地contour等高线
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值