【发布时间】:2017-09-20 09:37:13
【问题描述】:
所以,我可以让 sklearn.linear_model.LinearRegression 来处理我的数据 - 至少可以在不引发任何异常或警告的情况下运行脚本。唯一的问题是,我不是想用 matplotlib 绘制结果,而是想查看模型的估计量和诊断统计数据。
如何获得模型摘要,例如斜率和截距 (B0,B1)、R 平方调整等,以显示在控制台中或填充到变量中而不是绘制出来?
这是我运行的脚本的通用副本:
import numpy as p
import pandas as pn
from sklearn import datasets, linear_model
z = pn.DataFrame(
{'a' : [1,2,3,4,5,6,7,8,9],
'b' : [9,8,7,6,5,4,3,2,1]
})
a2 = z['a'].values.reshape(9,1)
b2 = z['b'].values.reshape(9,1)
reg = linear_model.LinearRegression(fit_intercept=True)
reg.fit(a2,b2)
# print(reg.get_params(deep=True)) I tried this and it didn't print out the #information I wanted
# print(reg) # I tried this too
这运行没有错误,但控制台中没有出现除此之外的输出:
{'n_jobs': 1, 'fit_intercept': True, 'copy_X': True, 'normalize': False} 线性回归(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)
感谢您提供有关如何获取此信息以打印模型摘要的任何信息。
【问题讨论】:
标签: python-3.x pandas scikit-learn regression linear-regression