Get startedGet started for free

Forecasting with ML Models

As a data science consultant, your task is to predict US hourly electricity demand. In the previous task, you cleaned and prepared the data. Now, it's time to use machine learning models to build your forecast.

We previously covered the statsforecast workflow, and now you'll apply the same principles using mlforecast.

The train and test datasets, as well as models (LGBMRegressor(), XGBRegressor(), LinearRegression()), are preloaded.

The MLForecast class has been imported from the mlforecast package, ready to use. Let’s build your forecast!

This exercise is part of the course

Forecasting in Practice

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Define the ML models to use in the forecast
ml_models = [____,  XGBRegressor(), LinearRegression()]

# Set up the MLForecast object with models, frequency, lags, and date features
mlf = ____(
    models= ____,  # Use the ML models
    freq='____',  # Set the frequency of your data (hourly)
    lags=list(range(1, 24)),  # Define time lags as features (previous 24 hours)
    date_features=['year', 'month', 'day', 'dayofweek', 'quarter', 'week', 'hour'])
Edit and Run Code