I tried using GradientBoostingClassifier in scikit-learn and it works fine with default options. However, when I tried to replace BaseEstimator with another classifier, it did not work and gave me the following error:
return y - np.nan_to_num(np.exp(pred[:, k] - IndexError: too many indices
You have a solution to the problem.
This error can be repaired using the following fragments:
import numpy as np from sklearn import datasets from sklearn.ensemble import GradientBoostingClassifier from sklearn.linear_model import LogisticRegression from sklearn.utils import shuffle mnist = datasets.fetch_mldata('MNIST original') X, y = shuffle(mnist.data, mnist.target, random_state=13) X = X.astype(np.float32) offset = int(X.shape[0] * 0.01) X_train, y_train = X[:offset], y[:offset] X_test, y_test = X[offset:], y[offset:]
The following is the full error response:
Traceback (most recent call last): File "/home/mohsena/Dropbox/programing/gbm/gb_with_init.py", line 56, in <module> clf.fit(X_train, y_train) File "/usr/local/lib/python2.7/dist-packages/sklearn/ensemble/gradient_boosting.py", line 862, in fit return super(GradientBoostingClassifier, self).fit(X, y) File "/usr/local/lib/python2.7/dist-packages/sklearn/ensemble/gradient_boosting.py", line 614, in fit random_state) File "/usr/local/lib/python2.7/dist-packages/sklearn/ensemble/gradient_boosting.py", line 475, in _fit_stage residual = loss.negative_gradient(y, y_pred, k=k) File "/usr/local/lib/python2.7/dist-packages/sklearn/ensemble/gradient_boosting.py", line 404, in negative_gradient return y - np.nan_to_num(np.exp(pred[:, k] - IndexError: too many indices
python numpy scikit-learn machine-learning ensemble-learning
iampat
source share