python api with live ercot real time prices
def calculate_model_accuracy_metrics(actual, predicted):
"""
Output model accuracy metrics, comparing predicted values
to actual values.
Arguments:
actual: list. Time series of actual values.
predicted: list. Time series of predicted values
Outputs:
Forecast bias metrics, mean absolute error, mean squared error,
and root mean squared error in the console
"""
#Calculate forecast bias
forecast_errors = [actual[i]-predicted[i] for i in range(len(actual))]
bias = sum(forecast_errors) * 1.0/len(actual)
print('Bias: %f' % bias)
#Calculate mean absolute error
mae = mean_absolute_error(actual, predicted)
print('MAE: %f' % mae)
#Calculate mean squared error and root mean squared error
mse = mean_squared_error(actual, predicted)
print('MSE: %f' % mse)
rmse = sqrt(mse)
print('RMSE: %f' % rmse)
#Execute in the main block
#Un-difference the data
for i in range(1,len(master_df.index)-1):
master_df.at[i,'Electricity_Price_Transformed']= master_df.at[i-1,'Electricity_Price_Transformed']+master_df.at[i,'Electricity_Price_Transformed_Differenced_PostProcess']
#Back-transform the data
master_df.loc[:,'Predicted_Electricity_Price']=np.exp(master_df['Electricity_Price_Transformed'])
#Compare the forecasted data to the real data
print(master_df[master_df['Predicted']==1][['Date','Electricity_Price', 'Predicted_Electricity_Price']])
#Evaluate the accuracy of the results
calculate_model_accuracy_metrics(list(master_df[master_df['Predicted']==1]['Electricity_Price']),
list(master_df[master_df['Predicted']==1 ['Predicted_Electricity_Price']))