吴恩达机器学习 Coursera 笔记(二) - 单变量线性回归(上)

简介: 吴恩达机器学习 Coursera 笔记(二) - 单变量线性回归

Model and Cost Function

1 模型概述 - Model Representation


To establish notation for future use, we’ll use


  • x(i)

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

  • y(i)

    denote the “output” or target variable that we are trying to predict (price).


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


  • X
    denote the space of input values
  • Y
    denote the space of output values

In this example

1.png

2.png

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

3.jpg

  • regression problem

When the target variable that we’re trying to predict iscontinuous, such as in our housing example

  • classification 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)

简单的介绍了一下数据集的表示方法,并且提出来h(hypothesis),即通过训练得出来的一个假设函数,通过输入x,得出来预测的结果y。并在最后介绍了线性回归方程


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.

1.jpg

首先需要搞清楚假设函数和代价函数的区别

当假设函数为线性时,即线性回归方程,其由两个参数组成:theta0和theta1

2.jpg

3.jpg


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

4.jpg

5.jpg

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:

image.png

image.png

3 代价函数(一)

image.png

image.png

image.png

When θ1=1, we get a slope of 1 which goes through every single data point in our model.

Conversely, when θ1=0.5, we see the vertical distance from our fit to the data points increase.

image.png

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=1 is our global minimum.

image.png

image.png

4 代价函数(二)

image.png

  • 等高线图是包含许多等高线的图形,双变量函数的等高线在同一条线的所有点处具有恒定值采用任何颜色并沿着’圆’,可得到相同的成本函数值
  • 当θ0= 800且θ1= -0.15时,带圆圈的x显示左侧图形的成本函数的值

取另一个h(x)并绘制其等高线图,可得到以下图表

image.png

例如,在上面的绿线上找到的三个红点具有相同的J(θ0,θ1)值,因此,它们能够被沿着同一条线找到


  • 当θ0= 360且θ1= 0时,等高线图中J(θ0,θ1)的值越接近中心,从而降低了成本函数误差
    现在给出我们的假设函数略微正斜率可以更好地拟合数据。


image.png

目录
相关文章
|
5月前
|
机器学习/深度学习 计算机视觉 Python
模型预测笔记(三):通过交叉验证网格搜索机器学习的最优参数
本文介绍了网格搜索(Grid Search)在机器学习中用于优化模型超参数的方法,包括定义超参数范围、创建参数网格、选择评估指标、构建模型和交叉验证策略、执行网格搜索、选择最佳超参数组合,并使用这些参数重新训练模型。文中还讨论了GridSearchCV的参数和不同机器学习问题适用的评分指标。最后提供了使用决策树分类器进行网格搜索的Python代码示例。
286 1
|
9月前
|
机器学习/深度学习 算法 数据可视化
技术心得记录:机器学习笔记之聚类算法层次聚类HierarchicalClustering
技术心得记录:机器学习笔记之聚类算法层次聚类HierarchicalClustering
84 0
|
9月前
|
机器学习/深度学习 分布式计算 API
技术好文:Spark机器学习笔记一
技术好文:Spark机器学习笔记一
62 0
|
9月前
|
机器学习/深度学习 算法 BI
机器学习笔记(一) 感知机算法 之 原理篇
机器学习笔记(一) 感知机算法 之 原理篇
|
9月前
|
机器学习/深度学习 人工智能 自然语言处理
算法金 | 吴恩达:机器学习的六个核心算法!
吴恩达教授在《The Batch》周报中介绍了机器学习领域的六个基础算法:线性回归、逻辑回归、梯度下降、神经网络、决策树和k均值聚类。这些算法是现代AI的基石,涵盖了从简单的统计建模到复杂的深度学习。线性回归用于连续变量预测,逻辑回归用于二分类,梯度下降用于优化模型参数,神经网络处理非线性关系,决策树提供直观的分类规则,而k均值聚类则用于无监督学习中的数据分组。这些算法各有优缺点,广泛应用于经济学、金融、医学、市场营销等多个领域。通过不断学习和实践,我们可以更好地掌握这些工具,发掘智能的乐趣。
157 1
算法金 | 吴恩达:机器学习的六个核心算法!
|
10月前
|
机器学习/深度学习 Python 索引
fast.ai 机器学习笔记(二)(4)
fast.ai 机器学习笔记(二)
78 0
fast.ai 机器学习笔记(二)(4)
|
10月前
|
索引 机器学习/深度学习 Python
fast.ai 机器学习笔记(二)(3)
fast.ai 机器学习笔记(二)
100 0
fast.ai 机器学习笔记(二)(3)
|
10月前
|
机器学习/深度学习 计算机视觉 算法
fast.ai 机器学习笔记(二)(2)
fast.ai 机器学习笔记(二)
97 0
fast.ai 机器学习笔记(二)(2)
|
10月前
|
索引 机器学习/深度学习 Python
fast.ai 机器学习笔记(二)(1)
fast.ai 机器学习笔记(二)
50 0
fast.ai 机器学习笔记(二)(1)
|
10月前
|
机器学习/深度学习 PyTorch 算法框架/工具
fast.ai 机器学习笔记(三)(4)
fast.ai 机器学习笔记(三)
91 0
fast.ai 机器学习笔记(三)(4)

热门文章

最新文章