Я новичок в концепции линейной регрессии в Python. Я использую линейную регрессию в scikit-learn, чтобы найти предсказанное значение y, здесь оно называется y_new. Ниже приведен код, который я написал до сих пор:
import numpy as np
#creating data for the run
x=spendings = np.linspace(0,5,4000)
y=sales = np.linspace(0,0.5,4000)
#defining the training function
def train(x,y):
from sklearn.linear_model import LinearRegression
model = LinearRegression().fit(x,y)
return model
model = train(x,y)
x_new = 23.0
y_new = model.predict([[x_new]])
print(y_new)
Я не могу получить значение y_new из-за этого сообщения об ошибке:
Expected 2D array, got 1D array instead:
array=[0.00000000e+00 1.25031258e-03 2.50062516e-03 ... 4.99749937e+00
4.99874969e+00 5.00000000e+00].
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.