Skip to content

Preparing a Forecast

After downloading the raw measurements data, the next step for Forecasters is to prepare their forecasts. This involves creating forecast submissions based on the retrieved data and any additional variables or models the Forecaster might utilize. In this example, we'll demonstrate how to prepare a simple 24-hour submission using randomly generated data. In a real-world scenario, you would replace this with your forecasting model based on the dataset retrieved in the previous step.

Note

  • Example Purpose: This example demonstrates preparing a 24-hour forecast submission with 15-minute interval samples using random data. Replace this with your forecasting model for actual use.
  • Quantiles: The example submission includes values for three variables, specifically 'quantiles' 10, 50, and 90.

Prerequisites

  • Python Environment: Ensure you have Python installed with the necessary libraries (pandas, numpy, requests).
  • Access Token: A valid access token is required for authentication. Refer to the Authentication section if needed.
  • Challenges List: A list of challenges retrieved from the Listing Challenges section.

Selecting a Challenge

First, select a challenge from the list of challenges you have retrieved:

submit_forecast.py
# Select the first challenge of the list of challenges previous retrieved
selected_challenge = challenges["data"][0]

# Unpack selected challenge information
resource_id = selected_challenge["resource"]
challenge_id = selected_challenge["id"]
start_datetime = selected_challenge["start_datetime"]
end_datetime = selected_challenge["end_datetime"]

Preparing Forecast Submissions Time-series Data

Next, prepare the forecast data for submission.

Important

In this example, our submission will be exclusively composed by random samples. However, you should prepare your model based on the raw measurements data for the challenge resource (see Downloading Raw Data section), and any external information sources you might have access to.

One variable at each time

You can only submit one forecast variable in each HTTPs request (e.g., forecasts for quantile 10 in the first request and quantile 50 in the second request).

submit_forecast.py
# Create a random 24h submission (random values):
# Generate datetime values for the challenge period:
datetime_range = pd.date_range(start=start_datetime,
                               end=end_datetime,
                               freq='15T')
datetime_range = [x.strftime("%Y-%m-%dT%H:%M:%SZ") for x in datetime_range]
# Generate random values for the "value" column
values = np.random.uniform(low=0.0, high=1.0, size=len(datetime_range))
values = [round(x, 3) for x in values]

# Reuse this data to prepare 3 different quantiles submissions Q10, Q50, Q90
submission_list = []
for qt in ["q10", "q50", "q90"]:
    qt_forec = pd.DataFrame({
    'datetime': datetime_range,
    'value': values,
    })
    submission_list.append({
        "variable": qt,
        "forecasts": qt_forec.to_dict(orient="records")
    })

# Your submissions:
print("Submission List:")
for i, submission in enumerate(submission_list):
    print("-"*79)
    print(f"Submission #{i+1}")
    print(json.dumps(submission, indent=3))

Download Full Example

What's next?

Learn how to submit your forecasts on the Predico platform in the Submitting a Forecast section.