我使用 scikit learn 進行了線性回歸
當我在測驗資料上看到我的均方誤差時,它非常低(0.09)
當我在測驗資料上看到我的 r2_score 時,它??也非常小(0.05)
據我所知,當均方誤差很低時,當前模型很好,但 r2_score 非常小,這告訴我們模型不好
我不明白我的回歸模型好不好
一個好的模型是否可以具有較低的 R 平方值,或者一個壞模型是否可以具有較低的均方誤差值?
uj5u.com熱心網友回復:
R^2 是衡量您的擬合代表資料的程度。
假設您的資料有一個線性趨勢和一些噪音。我們可以構建資料,看看 R^2 是如何變化的:
資料
我將使用numpy以下方法創建一些資料:
xs = np.random.randint(10, 1000, 2000)
ys = (3 * xs 8) np.random.randint(5, 10, 2000)

合身
現在我們可以使用 scikit 創建一個合適的物件
reg = LinearRegression().fit(xs.reshape(-1, 1), ys.reshape(-1, 1))
我們可以從這個擬合中得到分數。
reg.score(xs.reshape(-1, 1), ys.reshape(-1, 1))
我的 R^2 是: 0.9999971914416896
壞資料
假設我們有一組更分散的資料(上面有更多的噪音)。
ys2 = (3 * xs 8) np.random.randint(500, 1000, 2000)

現在我們可以計算 的分數ys2以了解我們的擬合代表xs,ys2資料的程度:
reg.score(xs.reshape(-1, 1), ys2.reshape(-1, 1))
我的 R^2 是: 0.2377175028951054
分數很低。我們知道資料的趨勢沒有改變。它仍然是 3x 8 (噪聲)。但ys2離合身更遠。
So, R^2 is an inductor of how good your fit is representing the data. But the condition of the data itself is important. Maybe even with low score the best possible fit is what you get. Since the data is scattered due to noise.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/339245.html
