运行模型预测时出错

时间:2018-06-16 08:33:02

标签: python pandas statsmodels

为模型运行以下预测

y_pred_m16 = lm_16.predict(X_test_m16)

我收到以下错误。有关为什么会发生这种情况的任何线索?

>ValueError                                Traceback (most recent call last)
<ipython-input-148-ff5c2d04d6a6> in <module>()
      1 # Making predictions
----> 2 y_pred_m16 = lm_16.predict(X_test_m16)

>~\AppData\Local\Continuum\anaconda3\lib\site-packages\statsmodels\base\model.py in predict(self, exog, transform, *args, **kwargs)
    790             exog = np.atleast_2d(exog)  # needed in count model shape[1]
    791 
--> 792         predict_results = self.model.predict(self.params, exog, *args, **kwargs)
    793 
    794         if exog_index is not None and not hasattr(predict_results, 'predicted_values'):

>~\AppData\Local\Continuum\anaconda3\lib\site-packages\statsmodels\regression\linear_model.py in predict(self, params, exog)
    259             exog = self.exog
    260 
--> 261         return np.dot(exog, params)
    262 
    263     def get_distribution(self, params, scale, exog=None, dist_class=None):

>ValueError: shapes (62,7) and (8,) not aligned: 7 (dim 1) != 8 (dim 0)

1 个答案:

答案 0 :(得分:1)

似乎训练和测试组具有不同的尺寸。您是否有可能通过8种功能进行培训并在7上进行测试?