[英]Using scikit LinearRegression.predict for multifeature labels
我正在嘗試使用它們作為特征來預測某個工作日(0-6)和某個時間的餐廳(=標簽)的顧客數量。 我的 dataframe 看起來像這樣:
我使 model 預測第一個可用數據點(第一行)的客戶數量的草圖是:
deg = 10 #the chosen polynomial degree
lin_regr = LinearRegression(fit_intercept=False) #linregr object
poly = PolynomialFeatures(degree=deg) #polynomial model
X_train_poly = poly.fit_transform(X_train) # fit the features
lin_regr.fit(X_train_poly, y_train)
print(lin_regr.predict([df.iloc[0]['weekday'], df.iloc[0]['acchour']]))
#The last line is causing the error
但是,我越來越
ValueError: Expected 2D array, got 1D array instead: array=[1. 6.75]
這背后的原因是什么,將這兩個功能提供給 function predict()
的正確語法是什么?
據我所知,您的數據點具有 (2,) 的形狀,並且必須是 (2,1)。 嘗試:
import numpy as np
datapoint=np.array([df.iloc[0]['weekday'], df.iloc[0]['acchour']]).reshape(-1,1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.