[英]single data to predict via linear regression model with more than one categorical feature
I built a linear regression model to predict the sales numbers for a product, In my case I have 5 features, 4 of them are categorical. 我建立了线性回归模型来预测产品的销售量。就我而言,我有5个功能,其中4个是分类功能。
MONTH REGION INTERVENANT CONFIG WEIGHT SALES_NB
I used OneHotEncoder 我使用了OneHotEncoder
from sklearn.preprocessing import OneHotEncoder
onehotencoder = OneHotEncoder(categorical_features = [0,1,2,3])
X = onehotencoder.fit_transform(X).toarray()
X = X [:, 1:]
(correct me if I am wrong) (如果我错了,请纠正我)
I want to know how do I format my data to pass it to predict(). 我想知道如何格式化数据以将其传递给predict()。 Actually if I pass: 实际上,如果我通过了:
Xnew = np.array([[2,2,14895,614,0.1]])
ynew = regressor.predict(Xnew)
I got this error: 我收到此错误:
ValueError: shapes (1,4) and (428,) not aligned: 4 (dim 1) != 428 (dim 0) ValueError:形状(1,4)和(428,)不对齐:4(dim 1)!= 428(dim 0)
Try encoding the new sample with onehotencoder
before you pass it to the predictor: 在将新样本传递给预测变量之前,请尝试使用onehotencoder
进行编码:
Xnew = np.array([[2,2,14895,614,0.1]])
Xnew_encoded = onehotencoder.transform(Xnew)
ynew = regressor.predict(Xnew_encoded)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.