什么是好的 R 平方分数?

What's a good R-squared score?

我 运行 这个线性回归代码,我使用 .score() 方法得到了 R 平方分数。然而,分数不容易理解,因为分数可能会变成负数。如果安装了 sklearn,代码可以 运行 在您的本地文件系统上。

代码:

from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
import numpy as np
boston = load_boston()
X = boston.data
y = boston['target']
X_roomns = X[:,5]
X_train, X_test, y_train, y_test = train_test_split(X_rooms, y)
reg = LinearRegression()
reg.fit(X_train.reshape(-1,1), y_train)
prediction_space = np.linspace(min(X_rooms), max(X_rooms)).reshape(-1,1)
plt.scatter(X_test, y_test)
plt.plot(prediction_space, reg.predict(prediction_space), color = 'black')
reg.score(X_test.reshape(-1,1), y_test)

谢谢!

R 平方分数低于 0(对于样本外数据,对于样本内数据这是不可能的)总是不好的,但除此之外它真的取决于用例。比较不同的模型比确定模型是否“足够好”更有用吗?评估模型是否足够好取决于推断信息的有用程度,这又取决于用例。