ValueError:从Y”的唯一值推断出的无效类。预期:[0 1 2 ... 1387 1388 1389],得到[0 1 2 ... 18609 24127 41850]
情况:我正在尝试使用XGBoost分类器,但是此错误弹出了我: “ valueerror:无效类是从y
的唯一值推断出的。 /em>。
与此解决的一个:从'y”的唯一值推断出无效的类。预期:[0 1 2 3 4 5],得到[1 2 3 4 5 6] ,看来我有一个不同的场景,该场景从0开始。
代码:
X = data_concat
y = data_concat[['forward_count','comment_count','like_count']]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=72)
#Train, test split
print ('Train set:', X_train.shape, y_train.shape) #Check the size after split
print ('Test set:', X_test.shape, y_test.shape)
xgb = XGBClassifier()
clf = xgb.fit(X_train, y_train, eval_metric='auc') #HERE IS WHERE GET THE ERROR
dataFRME和框架信息就是这样: dataframe
我采用了不同的y,这意味着当y的列或更多列时,列表” [0 1 2 ... 1387 1388 1388 1389] “将同时收缩或扩展。
如果您需要更多信息,请告诉我。感谢您的帮助:)
Situation: I am trying to use XGBoost classifier, however this error pops up to me:
"ValueError: Invalid classes inferred from unique values of y
. Expected: [0 1 2 ... 1387 1388 1389], got [0 1 2 ... 18609 24127 41850]".
Unlike this solved one: Invalid classes inferred from unique values of `y`. Expected: [0 1 2 3 4 5], got [1 2 3 4 5 6], it seems that I have a different scenario which is about not starting from 0.
Code:
X = data_concat
y = data_concat[['forward_count','comment_count','like_count']]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=72)
#Train, test split
print ('Train set:', X_train.shape, y_train.shape) #Check the size after split
print ('Test set:', X_test.shape, y_test.shape)
xgb = XGBClassifier()
clf = xgb.fit(X_train, y_train, eval_metric='auc') #HERE IS WHERE GET THE ERROR
The Datafrme and frame info is like this:
DataFrame
I have adopted different y, meaning when y has less or more columns, the list "[0 1 2 ... 1387 1388 1389]" will simultaneously shrink or expand.
If you need further info, please let me know. Appreciate your help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
需要转换y_train值以适合XGBoost,从0但不是1开始。
这是代码:
Need to transform the y_train value to fit xgboost, it starts from 0 but not 1.
Here is the code:
也许您的数据具有相同的大小,但是这些类的标签具有不同的值,例如,它必须为[1,2,3,4] IT返回[1,2,5,6]。如果您首先编码数据,然后出于某种原因将一些属于某些类中的编码值放下一些编码值,则可能发生这种情况。
Maybe your data have same size, but labels of those classes have different values, for example it must be [1,2,3,4] an it returns [1,2,5,6]. It can occur if you firstly encode your data and then drop some those encoded values that belong in some class for some reason.