Transforming backtesting output
Once backtesting is complete, you will need to transform the data in order to effectively evaluate the results and choose the best-performing model.
This exercise is part of the course
Designing Forecasting Pipelines for Production
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Restructure the DataFrame using pd.melt
models = list(ml_models.keys()) # Extract model names
bkt_long = pd.melt(
bkt_df,
id_vars=["unique_id", "ds", "cutoff", "y"], # Columns to keep
value_vars=models + [f"{____}-lo-95" for model in models] + [f"{____}-hi-95" for model in models], # Model columns
var_name="model_label", # Column for model labels
value_name="value", # Column for values
)
print(bkt_long.head())