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