scipy linregress的多变量线性回归 [英] Multi-variable linear regression with scipy linregress

查看:113
本文介绍了scipy linregress的多变量线性回归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试训练一个非常简单的线性回归模型.

I'm trying to train a very simple linear regression model.

我的代码是:

from scipy import stats

xs = [[   0,    1,  153]
 [   1,    2,    0]
 [   2,    3,  125]
 [   3,    1,   93]
 [   2,   24, 5851]
 [   3,    1,  524]
 [   4,    1,    0]
 [   2,    3,    0]
 [   2,    1,    0]
 [   5,    1,    0]]

ys = [1, 1, 1, 1, 1, 0, 1, 1, 0, 1]

slope, intercept, r_value, p_value, std_err = stats.linregress(xs, ys)

我遇到以下错误:

File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/stats/stats.py", line 3100, in linregress
ssxm, ssxym, ssyxm, ssym = np.cov(x, y, bias=1).flat
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/lib/function_base.py", line 1747, in cov
X = concatenate((X, y), axis)
ValueError: all the input array dimensions except for the concatenation 
axis must match exactly

我的输入有什么问题?我试图以几种方式更改 ys 的结构,但没有任何效果.

What's wrong with my input? I've tried changing the structure of ys in several ways but nothing works.

推荐答案

您正在寻找多变量回归.AFAIK stats.linregress 没有该功能.

You're looking for multi variable regression. AFAIK stats.linregress does not have that functionality.

您可能想尝试 sklearn.linear_model.LinearRegression .检查答案.

这篇关于scipy linregress的多变量线性回归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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