0
在Python StatsModel模塊中運行分位數迴歸後出現錯誤。該錯誤是以下幾點:StatsModel分位數迴歸ValueError
ValueError Traceback (most recent call last)
<ipython-input-221-3547de1b5e0d> in <module>()
16 model = smf.quantreg(fit_formula, train)
17
---> 18 fitted_model = model.fit(0.2)
19
20 #fitted_model.predict(test)
in fit(self, q, vcov, kernel, bandwidth, max_iter, p_tol, **kwargs)
177 resid = np.abs(resid)
178 xstar = exog/resid[:, np.newaxis]
--> 179 diff = np.max(np.abs(beta - beta0))
180 history['params'].append(beta)
181 history['mse'].append(np.mean(resid*resid))
ValueError: operands could not be broadcast together with shapes (178,) (176,)
我想它可能是通過不斷的特點造成的,所以我刪除這些,但我仍然得到了同樣的錯誤。我想知道是什麼原因。我的代碼如下:
quantiles = np.arange(.05, .99, .1)
cols = train.columns.tolist()[1:-2]
fit_formula = ''
for c in cols:
fit_formula = fit_formula + ' + ' + c
fit_formula = 'revenue ~ ' + train.columns.tolist()[0] + fit_formula
model = smf.quantreg(fit_formula, train)
fitted_model = model.fit(0.2)
感謝,這是完全回答我的問題。在刪除了不太嚴格的截斷相關特徵後,我能夠通過它。非常感謝! –
此行爲改變時的Bug問題是https://github.com/statsmodels/statsmodels/issues/3746 – user333700
很酷,謝謝。我會繼續跟蹤這張票。 –