Hi there,
I am just trying xgboost for my data set. My training file can be successfully loaded, but when I train the model I met the following error:
Traceback (most recent call last):
File "
File ".../xgboost/python-package/xgboost/training.py", line 205, in train
xgb_model=xgb_model, callbacks=callbacks)
File ".../xgboost/python-package/xgboost/training.py", line 21, in _train_internal
evals = list(evals)
TypeError: 'int' object is not iterable
My code is attached:
data_file = os.path.join(working_dir, 'training-data.liblinear')
dtrain = xgb.DMatrix(data_file)
param = {'max_depth':2, 'eta':1, 'silent':1, 'objective':'multi:softmax'}
num_round = 2
num_class= 10
bst = xgb.train(param, dtrain, num_round, num_class)
You should put num_class
in a param
dict.
Thank you very much! Now I have met the following error:
xgboost.core.XGBoostError: [17:19:30] src/objective/multiclass_obj.cc:75:
Check failed: label_error >= 0 && label_error < nclass
SoftmaxMultiClassObj: label must be in [0, num_class), num_class=10 but
found 10 in label.
I know the reason is that I have 10 classes labeled from 1 to 10, while the
program is expecting 0 to 9. How can I modify the DMatrix's label column
for that purpose? Many thanks!
Best,
linflyer
On Fri, Jul 8, 2016 at 5:00 PM, Artem Golubin [email protected]
wrote:
You should put num_class in param dict.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/dmlc/xgboost/issues/1343#issuecomment-231471429, or mute
the thread
https://github.com/notifications/unsubscribe/ACHF-zUP0S03FgTn6P6tZ2y3-qmpVK7eks5qTrpogaJpZM4JIL4_
.
What are your labels of your classes? Class is represented by a number and should be from 0 to num_class - 1. I had the same problem and this solved it.
i am getting the same error, need help to resolve
has anybody solve it, yet? I am still getting the error like below.
Here is my code
dtrain = xgb.DMatrix(X_train, label=y_train)
nc = len(np.unique(y_train))
param = {'objective':'multi:softmax',
'num_class': nc,
'max_depth': 8,
'eta' :0.3,
'eval_metric' : 'merror', # evaluation metric
'tree_method' : 'exact',
'silent': 0,
'nthread': -1}
model = xgb.train(param,dtrain, 20)
Below is the error:
[13:04:41] d:\build\xgboost\xgboost-git\dmlc-core\include\dmlc./logging.h:300: [13:0
4:41] D:\Build\xgboost\xgboost-git\src\objective\multiclass_obj.cc:75: Check failed:
label_error >= 0 && label_error < nclass SoftmaxMultiClassObj: label must be in [0, n
um_class), num_class=6 but found 37 in label.
As the error says, num_class is indeed 6. I found few more suggestions like use 'num_class = nc -1' or 'num_class = nc+1' but always getting the similar error. Is this a bug related to MultiClassObj?
Could somebody suggest a solution? Thanks in advance.
I have an update. My dataset has 6 classes but the class values were not sequential. The values were 0, 1, 2, 23, 24, and 37 and when I was passing 6 as num_class it was failing. Now, I changed the values to 0, 1, 2, 3, 4, 5 and it is working.
Error in xgb.iter.update(bst$handle, dtrain, iteration - 1, obj) :
[11:15:21] amalgamation/../src/objective/multiclass_obj.cc:75: Check failed: label_error >= 0 && label_error < nclass SoftmaxMultiClassObj: label must be in [0, num_class), num_class=2 but found 2 in label.
My NC =2. Number of class is my a binary. I am still getting a error.
However, when I was creating my Matrix using " One-Hot Encoding for factor variables.
I couldn't omit my dependent variable "COMPLIANT"
trainm <- sparse.model.matrix(COMPLIANT~ ., subset(training, select = - c(MEMBERKEY,SEX, TIN_DESC)))
my error is above.
@xavierjl70, try passing 3 as num_class. Because it considers 0 as a value.
Thank you so much. It works
Error in scale.default(bcsmdcare, center = min, scale = max - min) :
length of 'center' must equal the number of columns of 'x'
I am getting this error when i trying to scale my data to use Neural Network.
Does somebody have similar issue?
Thank you
I am running an auto.arima . however, I have to group by and loop.
by_StateCode <- group_by(p4pcrtcalsumm, StateCode, MeasureId)
fit1 = do(by_StateCode,tidy(auto.arima(RATE, seasonal= T, xreg=xi), data = p4pcrtcalsumm.
However, i am not able to predict or forecast. I am getting an error
frcst1 <- forecast(fits, h=10) or
mydata.pred1 <- do(by_StateCode,tidy(predict(fit1, n.ahead=10, data = p4pcrtcalsumm)))
error:
Error in ets(object, lambda = lambda, biasadj = biasadj, allow.multiplicative.trend = allow.multiplicative.trend, :
y should be a univariate time series
Error in xgb.iter.update(bst$handle, dtrain, iteration - 1, obj) :
[00:29:36] amalgamation/../src/objective/multiclass_obj.cc:78: Check failed: label_error >= 0 && label_error < nclass SoftmaxMultiClassObj: label must be in [0, num_class), num_class=2 but found 2 in label.
i tried passing num_class=3
and it worked for me
Most helpful comment
What are your labels of your classes? Class is represented by a number and should be from 0 to num_class - 1. I had the same problem and this solved it.