斯坦福大學機器學習作業題Problem Set #2 Logistic Regression: Training stability--上篇

斯坦福大學機器學習講義及作業題地址點擊打開鏈接

1. [15 points] Logistic Regression: Training stability

In this problem, we will be delving deeper into the workings of logistic regression. The goal of this problem is to help you develop your skills debugging machine learning algorithms(which can be very different from debugging software in general).Please do not modify the code for the logistic regression training algorithm for this problem.
First, run the given logistic regression code to train two different models on A and B.

數據來源dataA點擊打開鏈接

數據來源dataB點擊打開鏈接

代碼來源點擊打開鏈接

(a)What is the most notable difference in training the logistic regression model on datasets A and B?

運行後會發現dataA和dataB的收斂次數不一樣



(b) [5 points] Investigate why the training procedure behaves unexpectedly on datasetB, but not on A. Provide hard evidence (in the form of math, code, plots, etc.) to
corroborate your hypothesis for the misbehavior. Remember, you should address whyyour explanation does not apply to A.
Hint: The issue is not a numerical rounding or over/underow error.

本題中的主要思想就是通過梯度下降法計算邏輯迴歸係數,不斷迭代,通過計算本次迭代和上次迭代的差值的範數,判斷收斂性。本題選取的收斂域爲10的-15次方,可以看出A在30395步收斂,而B一直不收斂,通過printB的梯度,發現B的梯度還是在持續下降的,但是B的收斂速度過慢,所以遲遲不收斂,這也是梯度下降法本身的缺陷,梯度下降法是一階收斂越靠近收斂值的時候,收斂速度越來越慢,而本題中的學習係數爲固定值,當然也通過一維搜索確定學習係數的值

畫了個圖並沒有看出什麼太大區別

所以應該和梯度下降的梯度有關,此圖爲dataA的3萬次迭代中本次迭代和上次迭代的差值的範數

又研究了從第100次迭代開始的圖片,會發現其實在迭代幾千次之後收斂性已經還不錯了

接下來看下B的收斂速度


同樣研究了數據B從第100次迭代開始的圖片,


可以看出B的迭代速度比A慢,其實B也是可以收斂的,當我們調整收斂條件時,把收斂條件調大一些的時候,B也可以收斂,但是收斂速度仍然比A慢一些


發佈了32 篇原創文章 · 獲贊 3 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章