机器学习公开课笔记(1):机器学习简介及一元线性回归
初步介紹
監督式學習: 給定數據集并且知道其正確的輸出應該是怎么樣的,即有反饋(feedback),分為
- 回歸 (Regressioin): map輸入到連續的輸出值。
- 分類 (Classification):map輸出到離散的輸出值。
非監督式學習: 給定數據集,并不知道其正確的輸出是什么,沒有反饋,分為
- 聚類(Clustering): Examples: Google News, Computer Clustering, Markert Segmentation.
- 關聯(Associative):Examples: 根據病人特征估算其病癥.
一元線性回歸
假設(Hypothesis):$h_\theta(x)=\theta_0+\theta_1 x$
參數(Parameters):$\theta_0, \theta_1$
代價函數(Cost Function):$J(\theta_0, \theta_1) = \frac{1}{2m}\sum\limits_{i=1}^{m}\left(h_\theta(x^{(i)}) - y^{(i)}\right)^2$,最小二乘法
目標函數(Goal): $\min\limits_{\theta_0, \theta_1}J(\theta_0, \theta_1)$
梯度下降算法(Gradient descent)
基本思想:
- 初始化$\theta_0, \theta_1$
- 調整$\theta_0, \theta_1$直到$J(\theta_0, \theta_1)$達到最小值, 更新公式($\theta_j = \theta_j - \alpha\frac{\partial}{\partial \theta_j}J(\theta_0, \theta_1)$)
對于一元線性回歸問題,對$J(\theta_0, \theta_1)$求偏導數可得
$$\frac{\partial J}{\partial \theta_0} = \frac{1}{2m}\sum\limits_{i=1}^{m}2\times\left(\theta_0 +?\theta_1x^{(i)} - y^{(i)} \right) = \frac{1}{m}\sum\limits_{i=1}^{m}\left( h_\theta(x^{(i)}) - y^{(i)} \right)$$
$$\frac{\partial J}{\partial \theta_1} = \frac{1}{2m}\sum\limits_{i=1}^{m}2\times\left(\theta_0 +?\theta_1x^{(i)} - y^{(i)} \right)x^{(i)} = \frac{1}{m}\sum\limits_{i=1}^{m}\left( h_\theta(x^{(i)}) - y^{(i)} \right)x^{(i)}$$
從而參數$\theta_0, \theta_1$的更新公式為
$$\theta_0 = \theta_0 - \alpha\frac{1}{m}\sum\limits_{i=1}^{m}\left( h_\theta(x^{(i)}) - y^{(i)} \right)$$
$$\theta_1 = \theta_1 - \alpha\frac{1}{m}\sum\limits_{i=1}^{m}\left( h_\theta(x^{(i)}) - y^{(i)} \right)x^{(i)}$$
其中$\alpha$稱為學習速率(learning rate),如果其太小,則算法收斂速度太慢;反之,如果太大,則算法可能會錯過最小值,甚至不收斂。另一個需要注意的問題是,上面$\theta_0, \theta_1$的更新公式用到了數據集的全部數據 (稱為“Batch” Gradient Descent),這意味著對于每一次 update ,我們必須掃描整個數據集,會導致更新速度過慢。
線性代數復習
- 矩陣和向量定義
- 矩陣加法和數乘
- 矩陣-向量乘積
- 矩陣-矩陣乘積
- 矩陣乘法的性質:結合律,交換律不成立
- 矩陣的逆和轉置:不存在逆元的矩陣稱為“奇異(singular)矩陣”
參考文獻
[1] Andrew Ng Coursera 公開課第一周
轉載于:https://www.cnblogs.com/python27/p/MachineLearningWeek01.html
總結
以上是生活随笔為你收集整理的机器学习公开课笔记(1):机器学习简介及一元线性回归的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: BZOJ-1012[JSOI2008]最
- 下一篇: 第二百五十天 how can I 坚持