Lesson 55 of 60
pythonEnsemble Methods – Gradient Boosting (XGBoost)
30 minutes
Course progress92%
Gradient Boosting & XGBoost
Gradient boosting builds models sequentially, each new model correcting errors of its predecessor. XGBoost is a highly optimized implementation.
Installing XGBoost
pip install xgboost
Basic usage
import xgboost as xgb
from sklearn.metrics import accuracy_score
dtrain = xgb.DMatrix(X_train, label=y_train)
dtest = xgb.DMatrix(X_test, label=y_test)
params = {
: ,
: ,
: ,
: ,
: ,
: ,
:
}
bst = xgb.train(params, dtrain, num_boost_round=, evals=[(dtest, )], early_stopping_rounds=)
y_pred_proba = bst.predict(dtest)
y_pred = (y_pred_proba > ).astype()
(, accuracy_score(y_test, y_pred))