Oussama Jabri
Oussama Jabri

Reputation: 724

Error: "base_score > 0.0f && base_score < 1.0f base_score must be in (0,1) for logistic loss" on xgboost 0.7

I have a binary classification problem, and I wanted to try : XGBoost model since I have good results with GradientBoosting (sklearn) model on the same data set.

import xgboost as xgb

XGB = xgb.XGBClassifier()
model = XGB.fit(X_train, y_train)

But I have an error that I don't understand

XGBoostError: b'[11:52:35] src/objective/regression_obj.cc:48: Check failed: base_score > 0.0f && base_score < 1.0f base_score must be in (0,1) for logistic loss

Stack trace returned 10 entries:
[bt] (0) /home/ilb/anaconda3/lib/python3.6/site-packages/xgboost/./lib/libxgboost.so(_ZN4dmlc15LogMessageFatalD1Ev+0x29) [0x7f3bd4d15299]
[bt] (1) /home/ilb/anaconda3/lib/python3.6/site-packages/xgboost/./lib/libxgboost.so(_ZN7xgboost3obj18LogisticRegression12ProbToMarginEf+0x7e) [0x7f3bd4d9116e]
[bt] (2) /home/ilb/anaconda3/lib/python3.6/site-packages/xgboost/./lib/libxgboost.so(_ZN7xgboost11LearnerImpl13LazyInitModelEv+0x264) [0x7f3bd4d204a4]
[bt] (3) /home/ilb/anaconda3/lib/python3.6/site-packages/xgboost/./lib/libxgboost.so(XGBoosterUpdateOneIter+0x4a) [0x7f3bd4e69afa]
[bt] (4) /home/ilb/anaconda3/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(ffi_call_unix64+0x4c) [0x7f3ee8db6550]
[bt] (5) /home/ilb/anaconda3/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(ffi_call+0x1f5) [0x7f3ee8db5cf5]
[bt] (6) /home/ilb/anaconda3/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(_ctypes_callproc+0x3dc) [0x7f3ee8dad83c]
[bt] (7) /home/ilb/anaconda3/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(+0x9da3) [0x7f3ee8da5da3]
[bt] (8) /home/ilb/anaconda3/bin/../lib/libpython3.6m.so.1.0(_PyObject_FastCallDict+0x9e) [0x7f3f1f69792e]
[bt] (9) /home/ilb/anaconda3/bin/../lib/libpython3.6m.so.1.0(+0x147d1b) [0x7f3f1f773d1b]

Upvotes: 1

Views: 1260

Answers (4)

franchb
franchb

Reputation: 1204

I solved the problem by setting LC_ALL environment variable to en_US.UTF-8 after two hours of searching:

vim ~/.bashrc
export LC_ALL=en_US.UTF-8
source ~/.bashrc

The problem was when I used PySpark before XGBoost. The source of problem was JVM start as I could understand.

I want to point out that fixing this issue doesn't require applying not yet merged patch. Original patch issue highlights that root cause is locale-dependent code for parameter parsing. 0.5 is parsed as 0 because input is expected to be 0,5 under certain locales (for example, russian). You can avoid this error by enforcing en_US locale (especially LC_NUMERIC):

LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Build will pass fine with such settings. In my case locale slipped in on another host through ssh session because of SendEnv LANG LC_ setting in /etc/ssh/ssh_config*

Source: @frenzykryger answer here: Github Issue: xgboost for JVM has test failures

Upvotes: 1

Yiru GUO
Yiru GUO

Reputation: 1

it might be a typo in xgboost 0.7.0 version. i wrongly typied 'objective' to 'objectve', my code worked well. but after i changed back to the right word, this error showed.

Upvotes: 0

Eran Moshe
Eran Moshe

Reputation: 3208

Please try this and tell me if it helps:

param0 = [
    ('max_depth', 3),
    ('eta', 0.025),
    ('objective', 'binary:logistic'),
    ('min_child_weight', 4),
    ('silent', 1),
    ('eval_metric', 'auc'),
    ('subsample', 0.75),
    ('colsample_bytree', 0.75),
    ('gamma', 0.75),
]

dtrain = xgb.DMatrix(X_train, label=y_train)
watchlist = [(dtrain, "trn")]
num_round = 100
bst = xgb.train(param0, dtrain, num_round, evals=watchlist)

Upvotes: 1

Oussama Jabri
Oussama Jabri

Reputation: 724

I solved the problem by downgrading the xgboost package from xgboost 0.7 to xgboost 0.6a2.

Upvotes: 0

Related Questions