M.L.-Multivariate Linear Regression

Multiple Features


hypothesis function with multivariate


matrix form

1.Gradient Descent


gradient descent


Feature Scaling

We can speed up gradient descent by having each of our input values in roughly the same range. This is because θ will descend quickly on small ranges and slowly on large ranges, and so will oscillate inefficiently down to the optimum when the variables are very uneven.

x = x/(max-min,or range of feature)

Mean normalization

x = (x - u)/s , u is average of inputs, s is max - min

Learning Rate

Debugging gradient descent.Make a plot with?number of iterations?on the x-axis. Now plot the cost function, J(θ) over the number of iterations of gradient descent. If J(θ) ever increases, then you probably need to decrease α.

Automatic convergence test.Declare convergence if J(θ) decreases by less than E in one iteration, where E is some small value such as 10^?3. However in practice it's difficult to choose this threshold value.

To summarize:

If α is too small: slow convergence.

If α is too large: may not decrease on every iteration and thus may not converge.

Features and Polynomial Regression

Sometimes,the linear regression may not fit our data well,while there are polynomial regressions such as quadratic、cube蹋砚、or square functions can do better.

polynomial regression

One important thing to keep in mind is, if you choose your features this way then feature scaling becomes very important.

2.Normal Equation


Normal equation is another way to minimize J,we will minimize J by explicitly taking its derivatives with respect to the θj ’s, and setting them to zero. This allows us to find the optimum theta without iteration.

normal equation formula

compare to gradient descent:

(1) No need to choose alpha

(2) No need to iterate

(3) O (n^3), need to calculate inverse of X'X

(4) slow,if n is large

if X’X is noninvertible, two reasons:

.redundant features,where two features are very closely related (i.e. they are linearly dependent)

.Too many features (e.g. m ≤ n). In this case, delete some features or use "regularization" (to be explained in a later lesson).

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌涧衙,老刑警劉巖吧享,帶你破解...
    沈念sama閱讀 217,826評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異廊勃,居然都是意外死亡,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,968評論 3 395
  • 文/潘曉璐 我一進店門坡垫,熙熙樓的掌柜王于貴愁眉苦臉地迎上來梭灿,“玉大人,你說我怎么就攤上這事冰悠”ざ剩” “怎么了?”我有些...
    開封第一講書人閱讀 164,234評論 0 354
  • 文/不壞的土叔 我叫張陵溉卓,是天一觀的道長皮迟。 經(jīng)常有香客問我,道長桑寨,這世上最難降的妖魔是什么伏尼? 我笑而不...
    開封第一講書人閱讀 58,562評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮尉尾,結(jié)果婚禮上爆阶,老公的妹妹穿的比我還像新娘。我一直安慰自己沙咏,他們只是感情好辨图,可當我...
    茶點故事閱讀 67,611評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著肢藐,像睡著了一般故河。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上吆豹,一...
    開封第一講書人閱讀 51,482評論 1 302
  • 那天鱼的,我揣著相機與錄音,去河邊找鬼瞻讽。 笑死鸳吸,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的速勇。 我是一名探鬼主播,決...
    沈念sama閱讀 40,271評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼坎拐,長吁一口氣:“原來是場噩夢啊……” “哼烦磁!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起哼勇,我...
    開封第一講書人閱讀 39,166評論 0 276
  • 序言:老撾萬榮一對情侶失蹤都伪,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后积担,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體陨晶,經(jīng)...
    沈念sama閱讀 45,608評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,814評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了先誉。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片湿刽。...
    茶點故事閱讀 39,926評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖褐耳,靈堂內(nèi)的尸體忽然破棺而出诈闺,到底是詐尸還是另有隱情,我是刑警寧澤铃芦,帶...
    沈念sama閱讀 35,644評論 5 346
  • 正文 年R本政府宣布雅镊,位于F島的核電站,受9級特大地震影響刃滓,放射性物質(zhì)發(fā)生泄漏仁烹。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,249評論 3 329
  • 文/蒙蒙 一咧虎、第九天 我趴在偏房一處隱蔽的房頂上張望卓缰。 院中可真熱鬧,春花似錦老客、人聲如沸僚饭。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,866評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽鳍鸵。三九已至,卻和暖如春尉间,著一層夾襖步出監(jiān)牢的瞬間偿乖,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,991評論 1 269
  • 我被黑心中介騙來泰國打工哲嘲, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留贪薪,地道東北人。 一個月前我還...
    沈念sama閱讀 48,063評論 3 370
  • 正文 我出身青樓眠副,卻偏偏與公主長得像画切,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子囱怕,可洞房花燭夜當晚...
    茶點故事閱讀 44,871評論 2 354

推薦閱讀更多精彩內(nèi)容

  • 這個星期偷懶了霍弹,打卡不按時,以后不會了娃弓,輕易放棄的人生不會有好的結(jié)果典格。我會加油。 還是能看到成長的 不過台丛,我比較喜...
    隨便吧啥閱讀 214評論 2 0
  • 1耍缴、僅支持 Android 3.0 及以上版本(3.0 以下需手動加載Support庫) 2、最低sdk <use...
    潛沉閱讀 464評論 0 0
  • 子謂顏淵,曰:“惜乎防嗡!吾見其進也变汪,未見其止也”久” 哈皮波白話試譯: 孔子評價顏淵說到:“真是可惜耙唏谩!我只見到他一直...
    哈皮波閱讀 957評論 0 1