AndrewNg Machine Learning
绪论
Mar.9.2019
什么是机器学习?
- Arthur samuel 1959年创造了这个词 “Machine Learning”——Field of study that gives computers the ability to learn without being explicitly programmed.
“在没有明确设置的情况下,使计算机具有学习能力的研究领域。”
编写了跳棋程序,使机器自己与自己对弈,学会下棋。 - Tom Mitchell 1998 Well-posed Learning Problem:A computer program is said to learn from experience E with respect to some task T and some performance measure P,if its performance on T,as measured by P,improves with experience E.
“一个适当的学习问题定义如下:计算机程序从经验E中学习,解决某一个任务T,进行某一性能度量P,通过P测定在T上的表现因经验E而提高。”
Mar.10.2019
监督学习、无监督学习
- 监督学习(Supervised Learning):
我们给算法一个数据集,其中包含了数据对应的“正确答案”,算法的目的是找到更多正确答案。
- 连续值:也被称为“回归问题”:我们想要预测连续的数值输出。(房价和面积的例子)
- 离散值:分类问题、无穷多特征(肿瘤特征预测肿瘤良性恶性的例子)
- 无监督学习(Unsupervised Learning):
不提供“标准答案”,不给分类标准,要求找到数据集的结构,簇等。
- 聚类算法(clustering algorithms)比如谷歌的新闻分类。
- 鸡尾酒会算法:两个人同时说话,两个远近不同的麦克风同时记录,通过两个音频记录,无监督算法区分、分离出两个人的声音
算法代码:
[W,s,v] = svd((repmat(sum(x.*x,1),size(x,1),1).*x)*x’);
单变量线性回归
Mar.11.2019
模型描述
Hypothesis: h θ ( x ) = θ 0 + θ 1 x \text { Hypothesis: } \quad h_{\theta}(x)=\theta_{0}+\theta_{1} x Hypothesis: hθ(x)=θ0+θ1x
学习算法:根据训练集得到假设函数(Hypothesis)。
Mar.12.2019
代价函数
求线性假设函数的参数:代价函数(cost function),要求得使得代价函数最小的参数值。
代价函数最常用:平方误差函数
Hypothesis: h θ ( x ) = θ 0 + θ 1 x Parameters: θ 0 , θ 1 \begin{array}{l}{\text { Hypothesis: }} \\ {h_{\theta}(x)=\theta_{0}+\theta_{1} x} \\ \\ {\text { Parameters: }} \\ {\theta_{0}, \theta_{1}}\end{array} Hypothesis: hθ(x)=θ0+θ1x Parameters: θ0,θ1
J ( θ 0 , θ 1 ) = 1 2 m ∑ i = 1 m ( h θ ( x ( i ) ) − y ( i ) ) 2 J\left(\theta_{0}, \theta_{1}\right)=\frac{1}{2 m} \sum_{i=1}^{m}\left(h_{\theta}\left(x^{(i)}\right)-y^{(i)}\right)^{2} J(θ0,θ1)=2m1∑i=1m(hθ(x(i))−y(i))2
Goal: minimize J ( θ 0 , θ 1 ) \begin{array}{l}{\text { Goal: minimize } J\left(\theta_{0}, \theta_{1}\right)}\end{array} Goal: minimize J(θ0,θ1)
梯度下降
求代价函数的参数的算法,通过每次改变参数值,直到收敛,找到局部最优解。
α:学习率(决定每一轮的参数的更新幅度),取值不能过小(太慢),取值不能过大(导致无法收敛converge甚至发散diverge)
线性回归的梯度下降
将平方误差代价函数用于梯度下降
Gradient descent algorithm
repeat until convergence { θ 0 : = θ 0 − α 1 m ∑ i = 1 m ( h θ ( x ( i ) ) − y ( i ) ) θ 1 : = θ 1 − α 1 m ∑ i = 1 m ( h θ ( x ( i ) ) − y ( i ) ) ⋅ x ( i ) } \begin{array}{l} {\text { repeat until convergence } } \\ {\{} \\\\ {\theta_{0} :=\theta_{0}-\alpha \frac{1}{m} \sum_{i=1}^{m}\left(h_{\theta}\left(x^{(i)}\right)-y^{(i)}\right)} \\ {\theta_{1} :=\theta_{1}-\alpha \frac{1}{m} \sum_{i=1}^{m}\left(h_{\theta}\left(x^{(i)}\right)-y^{(i)}\right) \cdot x^{(i)} } \\\\ {\}}\end{array} repeat until convergence { θ0:=θ0−αm1∑i=1m(hθ(x(i))−y(i))θ1:=θ1−αm1∑i=1m(hθ(x(i))−y(i))⋅x(i)}
线性代数回顾
视频链接
内容程度大概是线性代数入门的两节课,可以略过。
配置
视频链接
根据自己的实验环境安装配置Octave和MATLAB
多变量线性回归
多功能
Hypothesis: h θ ( x ) = θ T x = θ 0 x 0 + θ 1 x 1 + θ 2 x 2 + ⋯ + θ n x n Parameters: θ 0 , θ 1 , … , θ n cost function: J ( θ 0 , θ 1 , … , θ n ) = 1 2 m ∑ i = 1 m ( h θ ( x ( i ) ) − y ( i ) ) 2 \begin{array}{l}{\text { Hypothesis: } h_{\theta}(x)=\theta^{T} x=\theta_{0} x_{0}+\theta_{1} x_{1}+\theta_{2} x_{2}+\cdots+\theta_{n} x_{n}} \\ {\text { Parameters: } \theta_{0}, \theta_{1}, \ldots, \theta_{n}} \\ {\text { cost function: }} \\ {J\left(\theta_{0}, \theta_{1}, \ldots, \theta_{n}\right)=\frac{1}{2 m} \sum_{i=1}^{m}\left(h_{\theta}\left(x^{(i)}\right)-y^{(i)}\right)^{2}}\end{array} Hypothesis: hθ(x)=θTx=θ0x0+θ1x1+θ