如何像 R 一样在 scikit-learn 中获得回归摘要? [英] How to get a regression summary in scikit-learn like R does?

查看:61
本文介绍了如何像 R 一样在 scikit-learn 中获得回归摘要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为 R 用户,我也想快速了解 scikit.

As an R user, I wanted to also get up to speed on scikit.

创建线性回归模型很好,但似乎无法找到一种合理的方法来获得回归输出的标准摘要.

Creating a linear regression model(s) is fine, but can't seem to find a reasonable way to get a standard summary of regression output.

代码示例:

# 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))

问题:

  • 似乎interceptcoef 内置于模型中,我只需输入print(倒数第二行)即可查看它们.
  • 所有其他标准回归输出(如 R^2、调整后的 R^2、p 值等)怎么样. 如果我正确阅读示例,似乎您必须编写函数/方程为每一个,然后打印它.
  • 那么,lin.c 没有标准的摘要输出吗?注册.模型?
  • 此外,在我打印的系数输出数组中,没有与每个相关联的变量名称?我只是得到了数字数组. 有没有办法打印这些,在那里我得到系数的输出和它们伴随的变量?
  • seems like the intercept and coef are built into the model, and I just type print (second to last line) to see them.
  • What about all the other standard regression output like R^2, adjusted R^2, p values, etc. If I read the examples correctly, seems like you have to write a function/equation for each of these and then print it.
  • So, is there no standard summary output for lin. reg. models?
  • Also, in my printed array of outputs of coefficients, there are no variable names associated with each of these? I just get the numeric array. Is there a way to print these where I get an output of the coefficients and the variable they go with?

我的打印输出:

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.

Notes: Started off with Linear, Ridge and Lasso. I have gone through the examples. Below is for the basic OLS.

推荐答案

sklearn 中没有 R 类型的回归总结报告.主要原因是 sklearn 用于预测建模/机器学习,评估标准基于对以前未见过的数据的性能(例如用于回归的预测 r^2).

There exists no R type regression summary report in sklearn. The main reason is that sklearn is used for predictive modelling / machine learning and the evaluation criteria are based on performance on previously unseen data (such as predictive r^2 for regression).

确实存在一个名为 sklearn.metrics.classification_report 的分类汇总函数,它计算分类模型上的几种(预测)分数.

There does exist a summary function for classification called sklearn.metrics.classification_report which calculates several types of (predictive) scores on a classification model.

要了解更经典的统计方法,请查看 statsmodels.

For a more classic statistical approach, take a look at statsmodels.

这篇关于如何像 R 一样在 scikit-learn 中获得回归摘要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆