Skip to content Skip to sidebar Skip to footer

Windows Error Using Xgboost With Python

So I'm tackling this machine-learning problem (from a previous Kaggle competition for practice: https://www.kaggle.com/c/nyc-taxi-trip-duration) and I'm trying to use XGBoost but g

Solution 1:

Well after struggling for a few days I managed to find a solution.

A friend of mine told xgboost is known to have problems with python 2.7 so I upgraded it to 3.6 This didn't entirely solve my problem but gave me a knew error:

OSError: [WinError 541541187] Windows Error0x20474343

After some digging I found a solution to this. The fit function I was trying to use was the source of the problem (although it did work on a different dataset so I'm not entirely sure why..).

Solution

change

classifier = XGBClassifier()
classifier.fit(X_train, y_train) 

to

dtrain = xgb.DMatrix(X_train, label=y_train)
dtest = xgb.DMatrix(X_test, label=y_test)
watchlist = [(dtrain, 'train'), (dtest, 'test')]
xgb_pars = {'min_child_weight': 1, 'eta': 0.5, 'colsample_bytree': 0.9, 
        'max_depth': 6, 'subsample': 0.9, 'lambda': 1., 'nthread': -1, 'booster' : 'gbtree', 'silent': 1, 'eval_metric': 'rmse', 'objective': 'reg:linear'}
model = xgb.train(xgb_pars, dtrain, 10, watchlist, early_stopping_rounds=2, maximize=False, verbose_eval=1)
print('Modeling RMSLE %.5f' % model.best_score)

Solution 2:

I guess the error is because you are using XGBClassfier instead of XGBRegressor for a regression problem.

Post a Comment for "Windows Error Using Xgboost With Python"