Skip to content

Commit

Permalink
refactor into metrics file
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed Dec 12, 2023
1 parent 7b64c0c commit d5bac61
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
Empty file.
29 changes: 29 additions & 0 deletions quartz_solar_forecast/eval/metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
def metrics(results_df):
"""
Calculate and print metrics: MAE
results_df dataframe with the following columns
- timestamp
- pv_id
- horizon_hours
- forecast_power
- generation_power
"""

mae = (results_df["forecast_power"] - results_df['generation_power']).abs().mean()
print(f"MAE: {mae}")

# calculate metrics over the different horizons hours
# find all unique horizon_hours
horizon_hours = results_df["horizon_hours"].unique()
for horizon_hour in horizon_hours:
# filter results_df to only include the horizon_hour
results_df_horizon = results_df[results_df["horizon_hours"] == horizon_hour]
mae = (results_df_horizon["forecast_power"] - results_df_horizon['generation_power']).abs().mean()
print(f"MAE for horizon {horizon_hour}: {mae}")

# TODO add more metrics using ocf_ml_metrics



6 changes: 3 additions & 3 deletions quartz_solar_forecast/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
This contains 50 sites each with 50 timestamps to make 2500 samples in total.
"""
from quartz_solar_forecast.eval.metrics import metrics
from quartz_solar_forecast.eval.nwp import get_nwp
from quartz_solar_forecast.eval.forecast import run_forecast
from quartz_solar_forecast.eval.utils import combine_forecast_ground_truth
Expand Down Expand Up @@ -35,9 +36,8 @@ def run_eval(testset_path):
results_df.to_csv("results.csv")

# Calculate and print metrics: MAE
mae = (results_df["forecast_power"] - results_df['generation_power']).abs().mean()
print(f"MAE: {mae}")
# TODO: add more metrics using ocf_ml_metrics
metrics(results_df)

# Visulisations


20 changes: 20 additions & 0 deletions tests/eval/test_metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from quartz_solar_forecast.eval.metrics import metrics
import pandas as pd
import numpy as np


def test_metrics():

# create a fake dataframe

results_df = pd.DataFrame(
columns=[
"id",
"timestamp",
"horizon_hours",
"forecast_power",
"generation_power",
], data=np.random.random((100,5)))

# call the metrics function
metrics(results_df)

0 comments on commit d5bac61

Please sign in to comment.