XGB Classifier error Invalid classes inferred from unique values of `y`

3.9k views Asked by At

This is my first question here. I've trained an XGB Classifier and it worked fine on local, but I'm trying the same in a jupyter notebook on a google cloud virtual machine and it gets an error.

My code:

`param_grid = {"max_depth": [3, None],
              "max_features": [20, 30, 40],
              "min_samples_split": [2, 3, 10],
              "bootstrap": [True, False],
              "error_score": ["raise"],
              "criterion": ["gini", "entropy"]}
xclas = XGBClassifier() 
grid = GridSearchCV(estimator=xclas, param_grid=param_grid, cv=5 )
grid.fit(X_res1, y_res1)`

The error output:

    Traceback (most recent call last):
  File "/opt/conda/lib/python3.7/site-packages/sklearn/model_selection/_validation.py", line 680, in _fit_and_score
    estimator.fit(X_train, y_train, **fit_params)
  File "/opt/conda/lib/python3.7/site-packages/xgboost/core.py", line 532, in inner_f
    return f(**kwargs)
  File "/opt/conda/lib/python3.7/site-packages/xgboost/sklearn.py", line 1358, in fit
    f"Invalid classes inferred from unique values of `y`.  "
ValueError: Invalid classes inferred from unique values of `y`.  Expected: [0 1 2 3 4 5 6 7 8], got [1 2 3 4 5 6 7 8 9]

I have read that this problem may occur when 'y' is not int type, but i've checked already and it is int. Could there be any way to solve this?

0

There are 0 answers