作为R用户,我也希望能够熟练使用scikit。
创建一个线性回归模型没问题,但似乎找不到一个合理的方式来得到标准的回归输出摘要。
代码示例:
# Linear Regression
import numpy as np
from sklearn import datasets
from sklearn.linear_model import LinearRegression
# Load the diabetes datasets
dataset = datasets.load_diabetes()
# Fit a linear regression model to the data
model = LinearRegression()
model.fit(dataset.data, dataset.target)
print(model)
# Make predictions
expected = dataset.target
predicted = model.predict(dataset.data)
# Summarize the fit of the model
mse = np.mean((predicted-expected)**2)
print model.intercept_, model.coef_, mse,
print(model.score(dataset.data, dataset.target))
问题:
- 看起来像 intercept 和 coef 已经嵌入到模型中,我只需输入
print
(倒数第二行)即可查看它们。 - 那么所有其他标准的回归输出,如R ^ 2,调整后的 R ^ 2,p 值等等呢?如果我正确读取了示例,则似乎您需要为每个输出编写一个函数/公式,然后打印它。
- 所以,线性回归模型没有标准摘要输出吗?
- 此外,在我的系数输出数组中,没有变量名称与每个系数关联?我只得到数字数组。 有没有一种方法可以打印这些系数,使其附带所属变量的输出?
我的输出结果:
LinearRegression(copy_X=True, fit_intercept=True, normalize=False)
152.133484163 [ -10.01219782 -239.81908937 519.83978679 324.39042769 -792.18416163
476.74583782 101.04457032 177.06417623 751.27932109 67.62538639] 2859.69039877
0.517749425413
说明:一开始使用了线性回归、岭回归和套索回归。我已经浏览了这些例子。以下是基本OLS的内容。
sklearn.metrics
中找到。 - Fred Foo