预期的二维数组,得到的是标量数组而不是错误
Expected 2D array, got scalar array instead error
我正在研究 python 3.7。执行下面的代码时出现错误。我该如何解决?
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
data = pd.read_csv("hw_25000.csv")
regression = LinearRegression()
boy= data.Height.values.reshape(-1,1)
kilo= data.Weight.values.reshape(-1,1)
regression.fit(boy,kilo)
regression.predict(70)
错误:
ValueError: Expected 2D array, got scalar array instead: array=1.
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.
hw_25000.csv:
Index,Height,Weight
1, 65.78331, 112.9925
2, 71.51521, 136.4873
3, 69.39874, 153.0269
4, 68.2166, 142.3354
你不能预测一个int,它必须是一个数组
reg.predict(np.array(70).reshape(-1, 1))
array([[141.94045785]])
我正在研究 python 3.7。执行下面的代码时出现错误。我该如何解决?
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
data = pd.read_csv("hw_25000.csv")
regression = LinearRegression()
boy= data.Height.values.reshape(-1,1)
kilo= data.Weight.values.reshape(-1,1)
regression.fit(boy,kilo)
regression.predict(70)
错误:
ValueError: Expected 2D array, got scalar array instead: array=1. 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.
hw_25000.csv:
Index,Height,Weight
1, 65.78331, 112.9925
2, 71.51521, 136.4873
3, 69.39874, 153.0269
4, 68.2166, 142.3354
你不能预测一个int,它必须是一个数组
reg.predict(np.array(70).reshape(-1, 1))
array([[141.94045785]])