machine learning week1-model Representation

线性回归算法

它被称作监督学习是因为对于每个数据来说 我们给出了 “正确的答案” 即告诉我们 根据我们的数据来说 房子实际的价格是多少 

而且 更具体来说 这是一个回归问题 .

回归一词指的是:我们根据之前的数据预测出一个准确的输出值 对于这个例子就是价格 。

另一种最常见的监督学习方式 叫做分类问题 当我们想要预测离散的输出值 例如 如果我们正在寻找 癌症肿瘤并想要确定 

肿瘤是良性的还是恶性的 这就是0/1离散输出的问题..

在监督学习中我们有一个数据集 

这个数据集被称训练集 因此对于房价的例子 我们有一个训练集 

包含不同的房屋价格 我们的任务就是从这个数据中学习预测房屋价格

 

Model Representation

To establish notation for future use, we’ll use x^{(i)}x(i) to denote the “input” variables (living area in this example), also called input features, and y^{(i)}y(i) to denote the “output” or target variable that we are trying to predict (price). A pair (x^{(i)} , y^{(i)} )(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)

 

如何把最有可能的直线与我们的数据相拟合

θ0和θ1 这些θi我把它们称为模型参数

 

Cost Function-Intuition I

 

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_\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(\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 \theta_1 = 1θ1​=1, we get a slope of 1 which goes through every single data point in our model. Conversely, when \theta_1 = 0.5θ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, \theta_1 = 1θ1​=1 is our global minimum.

 

Cost Function - Intuition II

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(\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 \theta_0θ0​ = 800 and \theta_1θ1​= -0.15. Taking another h(x) and plotting its contour plot, one gets the following graphs:

 

 

When \theta_0θ0​ = 360 and \theta_1θ1​ = 0, the value of 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 \theta_1θ1​ and \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'.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值