ValueError on sklearn's linear_model.predict


import numpy as np 
import pandas as pd
from sklearn import datasets, linear_model
df = pd.read_csv("homeprices.csv")
df
model = linear_model.LinearRegression()
model.fit(df[['area']], df.price)
model.predict(5000)

valueerror:预期的2D数组,取而代之的标量数组: 数组= 5000。 使用array.reshape(-1,1)重塑您的数据,如果您的数据具有单个功能或array.Reshape(1,-1),如果它包含一个示例。

更改线:

model.predict(5000)

to:

model.predict([[5000]])

最新更新