我正在尝试对数据进行线性回归。但是我的数据存在重塑问题。我收到此错误:
array=[1547977519 1547977513].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
这是我的代码:
from sklearn.linear_model import LinearRegression
X=[1547977519, 1547977513]
Y=[1, 1]
#X = X.reshape(-1, 1)
print(X)
#Y = Y.reshape(-1, 1)
print(Y)
reg = LinearRegression().fit(X, X)
print(reg.score(X, Y))
我尝试添加.reshape,但无法正常工作。它给了我这个错误:
X = X.reshape(-1, 1)
AttributeError: 'list' object has no attribute 'reshape'
答案 0 :(得分:1)
您正在寻找的是numpy.array
,它具有方法reshape
from numpy import array
>>> x = array([1547977519, 1547977513])
>>> x.reshape(-1,1)
array([[1547977519],
[1547977513]])