XGB分类器错误无效类从'y”的唯一值推断出

发布于 2025-01-24 13:02:28 字数 1209 浏览 4 评论 0原文

这是我在这里的第一个问题。我已经培训了一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文