Advertisement
Victor_Yovev

Untitled

Jan 25th, 2022
695
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class AnomalyFrame():
  2.   def __init__(self):
  3.     self.df = pd.DataFrame(columns=['alarm_at','error','actual'])
  4.  
  5.   def add_anomaly(self,index,error,actual):
  6.     new_anomaly= {'alarm_at':index,'error':error, 'actual':actual}
  7.     self.df=self.df.append(new_anomaly, ignore_index=True)
  8.  
  9.   def append_anomalyframe(self,df, predicted):
  10.     error = abs(df['count_emails']-predicted)
  11.     anomalies = df.iloc[detect_anomalies(error)]
  12.     new_df = pd.DataFrame(data={'alarm_at':anomalies.index, 'error':error.iloc[detect_anomalies(error)], 'actual':anomalies['count_emails']})
  13.     self.df=self.df.append(new_df,ignore_index=True)
  14.  
  15.   def agg(self,freq):
  16.     return self.df.resample(freq, on='alarm_at').count().rename(columns={'alarm_at':'#anomalies'}).drop(columns=['error','actual'],axis=1)
  17.  
  18.   def info(self, freq):
  19.     fig= plt.figure(figsize=(40,15))
  20.     new_df = self.agg(freq)
  21.     print(new_df.sort_values(by=['#anomalies'],ascending=False).head())
  22.     sb.lineplot(x=new_df.index, y=new_df['#anomalies'])
  23.     plt.show()
  24.  
  25.  
  26.   def __repr__(self):
  27.     print(self.df.tail(10))
  28.     return ""
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement