From 8379c88e22fffca5a3f0cd3b9e7e3094754bd3d5 Mon Sep 17 00:00:00 2001 From: rozetko Date: Mon, 25 Jun 2018 20:30:32 +0300 Subject: [PATCH] rm unused file --- analytics/prophet_algorithm.py | 46 ---------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 analytics/prophet_algorithm.py diff --git a/analytics/prophet_algorithm.py b/analytics/prophet_algorithm.py deleted file mode 100644 index f51c99d..0000000 --- a/analytics/prophet_algorithm.py +++ /dev/null @@ -1,46 +0,0 @@ -from fbprophet import Prophet -import pandas as pd - - -class prophet_algorithm(object): - def __init__(self): - self.model = None - self.dataset = None - - def fit(self, data, anomalies): - pass - - def predict(self, data): - data = data.reset_index() - data = data.rename(columns={'timestamp': 'ds', 'value': 'y'}) - self.dataset = data - - self.model = Prophet(yearly_seasonality=False, weekly_seasonality=False, daily_seasonality=True) - self.model.fit(self.dataset) - - future = self.model.make_future_dataframe(freq='H', periods=0, include_history=True) - forecast = self.model.predict(future) - cmp_df = forecast.set_index('ds')[['yhat', 'yhat_lower', 'yhat_upper']].join(self.dataset.set_index('ds')) - cmp_df['e'] = [ max(row.y - row.yhat_upper, row.yhat_lower - row.y, 0) for index, row in cmp_df.iterrows() ] - return self.__calc_anomalies(cmp_df) - - def __calc_anomalies(self, dataset): - anomalies = [] - cur_anomaly = None - for i in range(len(dataset)): - if dataset['e'][i] > 17: - if cur_anomaly is None: - cur_anomaly = {'start': dataset.index[i], 'finish': dataset.index[i], 'weight': 0} - cur_anomaly['finish'] = dataset.index[i] - cur_anomaly['weight'] += dataset['e'][i] - elif cur_anomaly is not None: - anomalies.append(cur_anomaly) - cur_anomaly = None - return anomalies - - -if __name__ == "__main__": - dataset = pd.read_csv('art_daily_flatmiddle.csv', index_col=['timestamp'], parse_dates=['timestamp']) - algo = prophet_algorithm(dataset) - res = algo.fit() - print(res) \ No newline at end of file