Expected 2D array, got 1D array instead: array=[1]

from sklearn import linear_model

lm=linear_model.LinearRegression()

features=['petallength']

x =iris[features]

y =iris['petalwidth']

print(x.shape,y.shape)

model=lm.fit(x,y)

print(model.intercept_,model.coef_)

model.predict([1])

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^