【发布时间】:2014-12-06 19:03:49
【问题描述】:
作为 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 值等)怎么样?如果我正确阅读示例,您似乎必须编写函数/方程对于其中的每一个,然后打印出来。
- 那么,是否没有针对 lin 的标准摘要输出。注册型号?
- 另外,在我打印的系数输出数组中,没有与每个相关的变量名?我只是得到数字数组。有没有办法打印这些我得到系数的输出和他们去的变量?
我的打印输出:
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中提供了许多标准评估指标。
标签: python r scikit-learn linear-regression summary