Improving performance Metrix in AutoBNN #25278
Unanswered
Opiyo-Inno
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone, i am trying to predict PAR data using the AutoBNN, however it is giving me very big values of MAE, RMSE and R-squared, i request for guidance on the changes to make in the code to make these values be between zero and 1.
here is the code i am running.
import jax
import jax.numpy as jnp
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from autobnn import estimators
from autobnn import training_util
Set up seed
seed = jax.random.PRNGKey(0)
Load your PAR data
data = pd.read_excel("D:/Work on PAR/PAR_data.xlsx")
data['date'] = pd.to_datetime(data[['year', 'month', 'day']])
data['value'] = data['PAR (W/m*2)']
Use daily data directly
PAR_daily = data['value'].to_numpy(dtype=np.float32)
num_forecast_steps = 365 * 3 # Forecast the last three years
PAR_training_data = PAR_daily[:-num_forecast_steps]
PAR_dates = data['date'].to_numpy()
fig, ax = plt.subplots(figsize=(16, 4))
ax.plot(PAR_dates[:-num_forecast_steps], PAR_training_data, lw=2)
plt.title("Daily PAR, Location Name")
plt.xlabel("Date")
plt.ylabel("PAR (W/m^2)")
Prepare training and test data
x_test = np.arange(len(PAR_daily), dtype=np.float32)
y_test = PAR_daily
x_train = x_test[:-num_forecast_steps]
y_train = PAR_training_data
x_scale = x_train.max()
x_train = x_train / x_scale
x_test = x_test / x_scale
one_year_period = jnp.array(365.0 / x_scale, dtype=jnp.float32) # daily data
fit_seed, pred_seed, seed = jax.random.split(seed, 3)
Enhanced model with added kernel components and more particles
est = estimators.AutoBnnMapEstimator(
'sum_of_products',
likelihood_model='normal_likelihood_logistic_noise',
seed=jax.random.PRNGKey(0),
periods=(one_year_period,),
num_particles=32, # Increased particles for better approximation
)
Fit the model to the training data
est = est.fit(x_train[..., None], y_train[..., None])
Predict PAR on the test data
preds = est.predict(x_test[..., None])
lo, mid, p90, hi = est.predict_quantiles(x_test[..., None], q=[2.5, 50., 90., 97.5])
_ = training_util.plot_results(PAR_dates,
preds,
dates_test=PAR_dates[-num_forecast_steps:],
y_test=PAR_daily[-num_forecast_steps:],
p2_5=lo,
p50=mid,
p97_5=hi,
dates_train=PAR_dates[:-num_forecast_steps],
y_train=PAR_daily[:-num_forecast_steps],
log_scale=False,
show_particles=False)
ax.set_xlabel("Date")
ax.set_ylabel("PAR (W/m^2)")
Analyze results
absolute_errors = abs(preds - y_test)
mae = absolute_errors.mean()
print("Mean Absolute Error (MAE):", mae)
squared_errors = (preds - y_test) ** 2
mean_squared_error = squared_errors.mean()
rmse = np.sqrt(mean_squared_error)
print("Root Mean Square Error (RMSE):", rmse)
Mean of actual values
y_mean = y_test.mean()
Total Sum of Squares (TSS)
tss = ((y_test - y_mean) ** 2).sum()
Residual Sum of Squares (RSS)
rss = ((y_test - preds) ** 2).sum()
r_squared = 1 - (rss / tss)
print("R-squared:", r_squared)
Beta Was this translation helpful? Give feedback.
All reactions