XGB分类器错误无效类从'y”的唯一值推断出
这是我在这里的第一个问题。我已经培训了一个XGB分类器,并且在本地上运行良好,但是我在Google Cloud Virtual Machine上的Jupyter笔记本中尝试了同样的方法,并且会出现错误。
我的代码:
`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)`
错误输出:
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]
我已经读到当“ y”不是int类型时可能会发生此问题,但是我已经检查了,并且是int。有什么办法可以解决这个问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论