-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Evaluate Continuous Ranked Probability Score as a Forecasting Perform…
…ance Measure #74 Added two tests
- Loading branch information
1 parent
6b652e9
commit 5386e02
Showing
2 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import pandas as pd | ||
import numpy as np | ||
|
||
import pyaf.ForecastEngine as autof | ||
import pyaf.Bench.TS_datasets as tsds | ||
|
||
b1 = tsds.load_airline_passengers() | ||
df = b1.mPastData | ||
|
||
df.head() | ||
|
||
|
||
lEngine = autof.cForecastEngine() | ||
lEngine | ||
|
||
H = b1.mHorizon; | ||
# lEngine.mOptions.enable_slow_mode(); | ||
lEngine.mOptions.mDebugPerformance = True; | ||
lEngine.mOptions.mModelSelection_Criterion = "CRPS" | ||
lEngine.mOptions.mParallelMode = True; | ||
lEngine.train(df , b1.mTimeVar , b1.mSignalVar, H); | ||
lEngine.getModelInfo(); | ||
|
||
print(lEngine.mSignalDecomposition.mTrPerfDetails.columns); | ||
lColumns = ['Split', 'Transformation', 'Model', 'Category', 'Complexity', | ||
'FitCRPS', 'ForecastCRPS', 'TestCRPS'] | ||
print(lEngine.mSignalDecomposition.mTrPerfDetails[lColumns].head(10)); | ||
|
||
lEngine.mSignalDecomposition.mBestModel.mTimeInfo.mResolution | ||
|
||
lEngine.standardPlots(name = "outputs/my_airline_passengers") | ||
|
||
dfapp_in = df.copy(); | ||
dfapp_in.tail() | ||
|
||
#H = 12 | ||
dfapp_out = lEngine.forecast(dfapp_in, H); | ||
dfapp_out.tail(2 * H) | ||
print("Forecast Columns " , dfapp_out.columns); | ||
lForecastColumnName = b1.mSignalVar + '_Forecast' | ||
Forecast_DF = dfapp_out[[b1.mTimeVar , b1.mSignalVar, lForecastColumnName , lForecastColumnName + '_Lower_Bound', lForecastColumnName + '_Upper_Bound' ]] | ||
print(Forecast_DF.info()) | ||
print("Forecasts\n" , Forecast_DF.tail(2*H)); | ||
|
||
print("\n\n<ModelInfo>") | ||
print(lEngine.to_json()); | ||
print("</ModelInfo>\n\n") | ||
print("\n\n<Forecast>") | ||
print(Forecast_DF.tail(2*H).to_json(date_format='iso')) | ||
print("</Forecast>\n\n") | ||
|
||
# lEngine.standardPlots(name = "outputs/airline_passengers") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from __future__ import absolute_import | ||
|
||
import pandas as pd | ||
import numpy as np | ||
|
||
|
||
import pyaf.ForecastEngine as autof | ||
import pyaf.Bench.TS_datasets as tsds | ||
|
||
|
||
b1 = tsds.load_ozone() | ||
df = b1.mPastData | ||
|
||
#df.tail(10) | ||
#df[:-10].tail() | ||
#df[:-10:-1] | ||
#df.describe() | ||
|
||
|
||
lEngine = autof.cForecastEngine() | ||
lEngine | ||
|
||
H = b1.mHorizon; | ||
# lEngine.mOptions.enable_slow_mode(); | ||
lEngine.mOptions.mDebugPerformance = True; | ||
lEngine.mOptions.mModelSelection_Criterion = "CRPS" | ||
lEngine.train(df , b1.mTimeVar , b1.mSignalVar, H); | ||
lEngine.getModelInfo(); | ||
|
||
print(lEngine.mSignalDecomposition.mTrPerfDetails.columns); | ||
lColumns = ['Split', 'Transformation', 'Model', 'Category', 'Complexity', | ||
'FitCRPS', 'ForecastCRPS', 'TestCRPS'] | ||
print(lEngine.mSignalDecomposition.mTrPerfDetails[lColumns].head(10)); | ||
|
||
lEngine.mSignalDecomposition.mBestModel.mTimeInfo.mResolution | ||
|
||
lEngine.standardPlots("outputs/my_ozone"); | ||
|
||
dfapp_in = df.copy(); | ||
dfapp_in.tail() | ||
|
||
#H = 12 | ||
dfapp_out = lEngine.forecast(dfapp_in, H); | ||
#dfapp_out.to_csv("outputs/ozone_apply_out.csv") | ||
dfapp_out.tail(2 * H) | ||
print("Forecast Columns " , dfapp_out.columns); | ||
Forecast_DF = dfapp_out[[b1.mTimeVar , b1.mSignalVar, b1.mSignalVar + '_Forecast']] | ||
print(Forecast_DF.info()) | ||
print("Forecasts\n" , Forecast_DF.tail(H)); | ||
|
||
print("\n\n<ModelInfo>") | ||
print(lEngine.to_json()); | ||
print("</ModelInfo>\n\n") | ||
print("\n\n<Forecast>") | ||
print(Forecast_DF.tail(2*H).to_json(date_format='iso')) | ||
print("</Forecast>\n\n") | ||
|