作为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))
问题:
print
(倒数第二行)即可看到它们。我的打印输出:
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
注意:从Linear,Ridge和Lasso开始。我已经看过这些例子。以下是基本OLS。
sklearn中没有R类型回归摘要报告。主要原因是sklearn用于预测建模/机器学习,而评估标准是基于先前未见数据(例如回归的预测r ^ 2)的性能。
确实存在用于分类的汇总函数,sklearn.metrics.classification_report
该函数可在分类模型上计算几种类型的(预测)分数。
有关更经典的统计方法,请参阅statsmodels
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句