XGBoosting Home | About | Contact | Examples

XGBoost for Multivariate Regression

XGBoost is a powerful tool for multivariate regression tasks, where the goal is to predict a continuous target variable based on multiple input features.

This example demonstrates how to fit an XGBoost model for multivariate regression using the scikit-learn API in just a few lines of code.

# xgboosting.com
# Fit an XGBoost Model for Multivariate Regression using scikit-learn API
from sklearn.datasets import make_regression
from xgboost import XGBRegressor

# Generate a synthetic dataset with 5 features
X, y = make_regression(n_samples=1000, n_features=5, noise=0.1, random_state=42)

# Initialize XGBRegressor
model = XGBRegressor(objective='reg:squarederror', random_state=42)

# Fit the model to training data
model.fit(X, y)

# Make predictions with the fit model
predictions = model.predict(X)

The key steps:

  1. Initialize an XGBRegressor with the appropriate objective (here, 'reg:squarederror' for regression with squared error loss).
  2. Fit the model to your training data using fit().
  3. Make predictions on new data using predict().

That’s it! You now have a working XGBoost model for multivariate regression. Experiment with different hyperparameters to fine-tune performance for your specific dataset and requirements.

See Also