XGBoost Regressor

Create an XGBoost regressor object.

Chapter Goals:

  • Learn how to create a scikit-learn style regression model in XGBoost

A. XGBoost linear regression

In addition to scikit-learn style classifiers, XGBoost also provides a scikit-learn style linear regression model with the XGBRegressor object.

Press + to interact
model = xgb.XGBRegressor(max_depth=2)
# predefined data and labels (for regression)
model.fit(data, labels)
# new_data contains 2 new data observations
predictions = model.predict(new_data)
print('Predictions:\n{}'.format(repr(predictions)))

Just like the XGBClassifier object, we can specify the model's parameters with keyword arguments. In the code above, we set the max_depth parameter (representing the depth of the boosted decision tree) to 2.

Get hands-on with 1300+ tech skills courses.