更新时间:2022-03-12 23:23:53
作为注释键入有点长,因此如果您在转换为Numpy数组之前查看x:
print([len(i) for i in x])
[36, 10, 10]
和y
的长度为3。可以进行线性回归,但每个观察值的自变量需要具有相同数量的变量。
在您的情况下,列表x
的第一个元素应该像其他元素一样具有10个条目。
例如:
import numpy as np
from sklearn import linear_model
clf = linear_model.LinearRegression()
# take the first ten
exo = np.array([i[:10] for i in x])
# fit
clf.fit(exo,np.array(y))
clf.coef_
array([ 8.12727273e-02, -6.93889390e-18, 8.12727273e-02, 0.00000000e+00,
0.00000000e+00, -2.70909091e-02, 5.41818182e-02, 8.12727273e-02,
2.70909091e-02, 0.00000000e+00])
您得到10个系数,x的每列一个系数。