dmlc / xgboost

Scalable, Portable and Distributed Gradient Boosting (GBDT, GBRT or GBM) Library, for Python, R, Java, Scala, C++ and more. Runs on single machine, Hadoop, Spark, Dask, Flink and DataFlow
https://xgboost.readthedocs.io/en/stable/
Apache License 2.0
26.08k stars 8.7k forks source link

Continue training with XGBClassifier() #4691

Closed roycechan closed 5 years ago

roycechan commented 5 years ago

I trained a XGBClassifier for 10 rounds. Is it possible to continue training later?

Here's how I saved the model after 10 rounds: joblib.dump(bst, 'model/xgbmodel.pkl.z')

When i try to train it subsequently

bst2 = joblib.load('model/xgbmodel.pkl.z') bst2.fit(X_train,y_train, eval_set=[(X_train, y_train), (X_test, y_test)], eval_metric='mlogloss', early_stopping_rounds = 5, verbose=True, xgb_model = bst2)

I get this error:

/opt/anaconda3/lib/python3.7/site-packages/xgboost/training.py in _train_internal(params, dtrain, num_boost_round, evals, obj, feval, xgb_model, callbacks) 36 if xgb_model is not None: 37 if not isinstance(xgb_model, STRING_TYPES): 38 xgb_model = xgb_model.save_raw() 39 bst = Booster(params, [dtrain] + [d[0] for d in evals], model_file=xgb_model) 40 nboost = len(bst.get_dump())

AttributeError: 'XGBClassifier' object has no attribute save_raw

hcho3 commented 5 years ago

Try:

bst2 = joblib.load('model/xgbmodel.pkl.z')
bst2.fit(X_train,y_train, eval_set=[(X_train, y_train), (X_test, y_test)],
         eval_metric='mlogloss', early_stopping_rounds = 5, verbose=True,
         xgb_model = bst2.get_booster())