Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structural pattern #95

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 50 additions & 7 deletions src/covidify/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from datetime import datetime, date, time
from sklearn.metrics import mean_squared_error
from covidify.config import PERC_SPLIT, FIG_SIZE
from abc import ABCMeta, abstractclassmethod


font = {'weight' : 'bold',
'size' : 22}
Expand Down Expand Up @@ -61,7 +63,39 @@
os.system('mkdir -p ' + image_dir)


def plot_forecast(tmp_df, train, index_forecast, forecast, confint):



class Createbuilder(metaclass = ABCMeta):
@staticmethod
def plot_forecast():
#plot - forecast into file

@staticmethod
def forecast():
#saving data





if __name__ == '__main__':
print('Training forecasting model...')

train = trend_df[trend_df.date.isin(train_period)].cumulative_cases
index_forecast = [x for x in range(train.index[-1]+1, train.index[-1] + days_in_future+1)]
forecast(trend_df, train, index_forecast, days_in_future)

# Using the Builder pattern makes sense only when your products
# are quite complex and require extensive configuration. The
# following two products are related, although they don't have
# a common interface.

class ForcastBuilder(Createbuilder):
def __init__(self):
self.result = Result()

def plot_forecast(tmp_df, train, index_forecast, forecast, confint):
'''
Plot the values of train and test, the predictions from ARIMA and the shadowing
for the confidence interval.
Expand Down Expand Up @@ -89,7 +123,7 @@ def plot_forecast(tmp_df, train, index_forecast, forecast, confint):
fig.savefig(os.path.join(image_dir, 'cumulative_forecasts.png'))


def forecast(tmp_df, train, index_forecast, days_in_future):
def forecast(tmp_df, train, index_forecast, days_in_future):

# Fit model with training data
model = auto_arima(train, trace=False, error_action='ignore', suppress_warnings=True)
Expand All @@ -108,9 +142,18 @@ def forecast(tmp_df, train, index_forecast, days_in_future):

plot_forecast(forecast_df, train, index_forecast, forecast, confint)

if __name__ == '__main__':
print('Training forecasting model...')

train = trend_df[trend_df.date.isin(train_period)].cumulative_cases
index_forecast = [x for x in range(train.index[-1]+1, train.index[-1] + days_in_future+1)]
forecast(trend_df, train, index_forecast, days_in_future)

class Result():
def __init__(self):
#this will reset
self.forecast = pd.DataFrame()


class Main():
@staticmethod
def construct();
return ForcastBuilder().
/forecast(pd.DataFrame(),train, index_forecast, days_in_future)

Result = Main.construct():