这是我要运行的Python代码。
这是我收到的错误信息。
from numpy import *
import pylab as pl
from sklearn.utils import shuffle
from sklearn.metrics import mean_squared_error
from sklearn import datasets
from sklearn.ensemble import AdaBoostRegressor
boston = datasets.load_boston()
X, y = shuffle(boston.data, boston.target)
offset = int(0.7*len(X))
X_train, y_train = X[:offset], y[:offset]
X_test, y_test = X[offset:], y[offset:]
regressor = AdaBoostRegressor(n_estimators=5)
regressor.fit(X_train, y_train)
x = [11.95, 0.00, 18.100, 0, 0.6590, 5.6090, 90.00, 1.385, 24, 680.0, 20.20, 332.09, 12.13]
y = regressor.predict(x)
print "Prediction for " + str(x) + " = " + str(y)
这是我收到的错误信息。
Traceback (most recent call last):
File "bug.py", line 18, in <module>
y = regressor.predict(x)
File "/usr/local/lib/python2.7/dist-packages/sklearn/ensemble/weight_boosting.py", line 1075, in predict
return self._get_median_predict(X, len(self.estimators_))
File "/usr/local/lib/python2.7/dist-packages/sklearn/ensemble/weight_boosting.py", line 1050, in _get_median_predict
median_estimators = sorted_idx[np.arange(X.shape[0]), median_idx]
IndexError: index 1 is out of bounds for axis 0 with size 1
我可以将回归函数更改为KNeighborsRegressor或DecisionTreeRegressor,它们都能给出良好的预测结果。
我不确定该如何解决这个问题。感谢您的所有帮助。