def setUp(self): self.data_location = 'data/daily-min-temperatures.csv' self.plot_save_location = '/home/boats/Desktop/' self.target_df = importDataFrame(self.data_location) self.split_date = pd.to_datetime('1986-01-01 00:00:00') self.train_df = makeTrainDF(self.target_df, self.split_date) self.valid_df = makeValidationDF(self.target_df, self.split_date) self.empty_pred_df = makeEmptyPredictionDF(self.target_df, self.split_date) self.pred_df = LastValueModel.create_prediction( self.train_df, self.empty_pred_df) self.test_model = PredictionModel('test name') def dummy_pred_fn(train_df, empty_pred_df): last_value = (train_df[train_df['dt'] == train_df['dt'] .max()]['val']) pred_df = empty_pred_df.copy(deep=True) pred_df['val'] = last_value return pred_df self.test_model.predict = dummy_pred_fn self.pred_df_from_model = self.test_model.predict(self.train_df, self.empty_pred_df) self.plot_df = self.test_model.present_results( self.train_df, self.valid_df, self.pred_df, self.plot_save_location )
def test_user_journey(self): # Ivan just downloaded some data and wants to play with it # He makes a dataframe from the csv self.df = importDataFrame(self.DATA_LOCATION) self.assertIsNotNone(self.df) # He determines the split date and creates train and validation dfs self.split_date = '1987-01-01' self.train = makeTrainDF(self.df, self.split_date) self.valid = makeValidationDF(self.df, self.split_date) self.empty_pred = makeEmptyPredictionDF(self.df, self.split_date) # He decides to apply the Naive prediction model self.LV_pred = LastValueModel.create_prediction( self.train, self.empty_pred) # He then wants to admire the results of his hard work in a png file LastValueModel.present_results(self.train, self.valid, self.LV_pred, self.PLOT_SAVE_LOCATION) # He also wants to see the performance of the model on MAE and RMSE self.MAE_val = MAE.calculate_performance(self.valid, self.LV_pred) self.RMSE_val = RMSE.calculate_performance(self.valid, self.LV_pred) self.assertGreater(self.MAE_val, 0.0) self.assertGreater(self.RMSE_val, 0.0) # Satisfied, he now moves on to Prophet. # He creates the prediction self.PH_pred = ProphetModel.create_prediction(self.train, self.empty_pred) # He plots the result in a png file ProphetModel.present_results(self.train, self.valid, self.PH_pred, self.PLOT_SAVE_LOCATION)
def setUp(self): self.data_location = 'data/daily-min-temperatures.csv' self.plot_name = 'plots/plot.png' self.target_df = importDataFrame(self.data_location) self.split_date = pd.to_datetime('1987-01-01 00:00:00') self.train_df = makeTrainDF(self.target_df, self.split_date) self.valid_df = makeValidationDF(self.target_df, self.split_date) self.empty_pred_df = makeEmptyPredictionDF(self.target_df, self.split_date) self.ph_pred = ProphetModel.create_prediction( self.train_df, self.empty_pred_df)
def setUp(self): self.data_location = 'data/daily-min-temperatures.csv' self.target_df = importDataFrame(self.data_location) self.split_date = pd.to_datetime('1987-01-01 00:00:00') self.train_df = makeTrainDF(self.target_df, self.split_date) self.valid_df = makeValidationDF(self.target_df, self.split_date) self.empty_pred_df = makeEmptyPredictionDF(self.target_df, self.split_date) self.pred_df = LastValueModel.create_prediction( self.train_df, self.empty_pred_df) self.MAPE = LossFunction(name='MAPE') def calc_MAPE(valid_df, pred_df): test = valid_df['val'].sub(pred_df['val']) test = test.sum() return test self.MAPE.calculate_performance = calc_MAPE
def setUp(self): self.data_location = 'data/daily-min-temperatures.csv' self.plot_name = 'plots/plot.png' self.target_df = importDataFrame(self.data_location) self.split_date = pd.to_datetime('1987-01-01 00:00:00') self.train_df = makeTrainDF(self.target_df, self.split_date) self.valid_df = makeValidationDF(self.target_df, self.split_date) self.empty_pred_df = makeEmptyPredictionDF(self.target_df, self.split_date) self.ph_pred = ProphetModel.create_prediction( self.train_df, self.empty_pred_df) self.train_df['label'] = 'train' self.valid_df['label'] = 'validation' self.ph_pred['label'] = 'prediction' self.merged_df = pd.concat([self.train_df, self.ph_pred, self.valid_df]) self.merged_pivot = self.merged_df.pivot_table(index='dt', columns='label', values='val')
def setUp(self): self.data_location = 'data/daily-min-temperatures.csv' self.target_df = importDataFrame(self.data_location) self.split_date = pd.to_datetime('1986-01-01 00:00:00') self.empty_pred_df = makeEmptyPredictionDF(self.target_df, self.split_date)
def setUp(self): self.data_location = 'data/daily-min-temperatures.csv' self.my_test_ts = importDataFrame(self.data_location) self.column_names = self.my_test_ts.columns