Machine Learning:Model and Cost Function

Model Representation

x(i) to denote the “input” variables (living area in this example), also called input features

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.

"(i)” in the notation is simply an index into the training set

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.
在这里插入图片描述
在这里插入图片描述

假设h(x)=θ1x,则代价函数J(θ1)只有一个参数

当θ1=1时,J(1)=0
在这里插入图片描述
当θ1=0.5时,J(0.5)=0.58333
在这里插入图片描述
将其他点都描绘出来可得下图,作为目标,我们要最小化代价函数,所以当θ1=1时,有最小值为0
在这里插入图片描述

假设h(x)=θ1+θ0x,则代价函数J(θ0,θ1)有两个参数

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.

当θ0=800,θ1=-0.15时
在这里插入图片描述
当θ0=360,θ1=0时
在这里插入图片描述
当θ0在250左右,θ1在0.12左右时,有接近最小值的J(θ0,θ1),最小值位于最里面圆的中心
在这里插入图片描述

发布了25 篇原创文章 · 获赞 0 · 访问量 1498

猜你喜欢

转载自blog.csdn.net/u014681799/article/details/101980052