Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AnomalyFrame():
- def __init__(self):
- self.df = pd.DataFrame(columns=['alarm_at','error','actual'])
- def add_anomaly(self,index,error,actual):
- new_anomaly= {'alarm_at':index,'error':error, 'actual':actual}
- self.df=self.df.append(new_anomaly, ignore_index=True)
- def append_anomalyframe(self,df, predicted):
- error = abs(df['count_emails']-predicted)
- anomalies = df.iloc[detect_anomalies(error)]
- new_df = pd.DataFrame(data={'alarm_at':anomalies.index, 'error':error.iloc[detect_anomalies(error)], 'actual':anomalies['count_emails']})
- self.df=self.df.append(new_df,ignore_index=True)
- def agg(self,freq):
- return self.df.resample(freq, on='alarm_at').count().rename(columns={'alarm_at':'#anomalies'}).drop(columns=['error','actual'],axis=1)
- def info(self, freq):
- fig= plt.figure(figsize=(40,15))
- new_df = self.agg(freq)
- print(new_df.sort_values(by=['#anomalies'],ascending=False).head())
- sb.lineplot(x=new_df.index, y=new_df['#anomalies'])
- plt.show()
- def __repr__(self):
- print(self.df.tail(10))
- return ""
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement