Andrew Ng machine learning (two) - cost function

Examples of prices by Wu explain in simple terms the cost function, the video of the cost function is to find the closest arguments prices data.

House price model cost function

The cost function helps us figure out how to put the most likely function and fit with our data. For example, in the model that we have trained in the training set (x, y), x represents the area of ​​housing, y represents the price of housing, we have to get a function hθ (x) (assuming that the function is called) by linear regression to as x independent variable, y as the dependent variable, a function to predict the price of a given area in the house.

Parameter θ0 and θ1 changes cause changes in assumptions function, determines the selection of parameters we get a straight line with respect to the accuracy of the training set, a gap value and values ​​in a training model predictions obtained is called modeling error (i.e. the blue line in the drawing)

Our goal is to choose envoy minimum square error model parameters in the regression analysis, we substituted monovalent function , even if the minimum value J (θ0, θ1) of.

Suppose θ0 = 0, seeking simplified version of the cost function

Θ0 is assumed equal to 0

We (x) function takes the specific value when θ1 = 1 to H, a given number of result sets (1,1), (2,2), (3,3), that h (x) = x when, corresponding J (θ) = 0

When the time θ1 = 0.5, i.e., h (x) = 0.5x, the corresponding J (θ) = 0.58

When θ1 = 0, i.e., h (x) = x when, the corresponding J (θ) = 2.3

The above demand is a simplified version of the cost function, if the theta] 0 also add parameter J (θ0, θ1) is a bowl of FIG.

With this corresponding to FIG drawn contour lines, which is a bunch of oval, ellipse corresponding to each of J (θ0, θ1) are the same value, if we take a point of the contour lines (800, - 0.15) can be drawn corresponding to hθ (x) of FIG.

When θ0 = 360, θ1 = 0 when, hθ (x) is a horizontal line

We continue to value the center of the ellipse can be a good acquisition hθ (x) in line with the results of a given set of functions, the result set will be almost evenly distributed around hθ (x) function, this function allows straight optimally proposed these data together.

Briefly, the difference between the predicted and actual values ​​of the current model is a cost function that is obtained by. This difference is a function of the model parameters, the smaller the better hope it

Published 80 original articles · won praise 140 · views 640 000 +

Guess you like

Origin blog.csdn.net/linjpg/article/details/103848501