testing = data[testing_start:testing_end] print(f'iteration {index}/{length}') print('--------------------------------') print() # arima print( f'fitting ARIMA model for location {location} and month {month} at {datetime.now()}' ) with warnings.catch_warnings(): warnings.filterwarnings( 'error', message='divide by zero encountered in double_scalars') try: arima = ARIMAModel(scaling=True) arima.fit(training, order=order, seasonal_order=seasonal_order, filter=filter, use_exogenous=True) prediction = arima.predict(testing_data=testing) error_nrmse = nrmse(testing.power, prediction.power) error_r2 = r2(testing.power, prediction.power) df.loc[f'{location}_{month}'].nrmse_arima = error_nrmse df.loc[f'{location}_{month}'].r2_arima = error_r2 print(f'nRMSE: {error_nrmse}; R2: {error_r2}') except Exception as e: print(
from importers import pvwatts from predictors.arima_model import ARIMAModel from evaluation.error_terms import mse, rmse, nrmse import matplotlib.pyplot as plt from pandas.plotting import register_matplotlib_converters; register_matplotlib_converters() # fix pandas future warnings # load data data = pw.load(lat=52.470001220703125, lon=13.399999618530273) # station in berlin # prepare testing and training data training = data['20190104':'20190131'] # use 4 weeks in january for training testing = data['20190201':'20190202'] # use 2 days in february for testing # prepare model model = ARIMAModel(scaling=True) model.fit(training, order=(3,0,1), seasonal_order=(3,0,3,24), filter=['tamb'], use_exogenous=True) model.predict(testing_data=testing) # evaluate model print(f'MSE: {mse(testing.power, model.prediction.power)}') print(f'RMSE: {rmse(testing.power, model.prediction.power)}') print(f'nRMSE: {nrmse(testing.power, model.prediction.power)}') # plot testing features plt.plot(testing.tamb, color='red') plt.show() # plot prediction and expected power output plt.plot(testing.power, color='red') plt.plot(model.prediction.power, color='orange') plt.show()
# one time without exogenous variables (arima only) columns = { 'features': 'none', 'svr_jan': math.nan, 'svr_april': math.nan, 'svr_july': math.nan, 'svr_oct': math.nan } for month, dates in datestrings: training_start, training_end, testing_start, testing_end = dates training = data[training_start:training_end] testing = data[testing_start:testing_end] # arima print(f'fitting arima model without exogenous variables for {month}...') arima = ARIMAModel(scaling=True) arima.fit_auto(training, p=(1, 3), q=(1, 3), P=(1, 3), Q=(1, 3), d=0, D=0, use_exogenous=False) print( f'fitted arima model successfully with order={arima.model.order}, seasonal_order={arima.model.seasonal_order}' ) prediction = arima.predict(hours=48) error = rmse(testing.power, prediction.power) print(f'RMSE: {error}') print()
for location, [data, base_data] in { 'edwards': [edwards, edwards_base], 'car_park': [car_park, car_park_base] }.items(): columns = {} for month, dates in datestrings: training_start, training_end, testing_start, testing_end = dates training = data[training_start:training_end] testing = data[testing_start:testing_end] # arima print( f'fitting ARIMA model for location {location} and month {month} at {datetime.now()}' ) try: arima = ARIMAModel(scaling=True) # arima.fit(training, order=order, seasonal_order=seasonal_order, filter=filter, use_exogenous=True) arima.fit_auto(training, p=p, q=q, P=P, Q=Q, d=0, D=0, filter=filter, trace=False, use_exogenous=True) print( f'successfully fitted ARIMA model with order={arima.model.order}; seasonal_order={arima.model.seasonal_order}' ) prediction = arima.predict(testing_data=testing)