File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ # -*- coding: utf-8 -*-
2
+ import numpy as np
3
+
4
+ def find_anomalies_z_score (list_data ):
5
+ outliers = []
6
+
7
+ std_data = np .std (list_data ); print ('std:' , std_data )
8
+ mean_data = np .mean (list_data ); print ('mean:' , mean_data )
9
+ anomaly_cut_off = std_data * 3 ; print ('anomaly_cut_off:' , anomaly_cut_off )
10
+
11
+ lower_limit = mean_data - anomaly_cut_off ; print ('lower_limit' , lower_limit )
12
+ upper_limit = mean_data + anomaly_cut_off ; print ('upper_limit' , upper_limit )
13
+
14
+ for outlier in list_data :
15
+ if outlier > upper_limit or outlier < lower_limit :
16
+ outliers .append (outlier )
17
+
18
+ if len (outliers ) == 0 :
19
+ print ('outlier is not found' )
20
+
21
+ return outliers
22
+
23
+ if __name__ == '__main__' :
24
+ data = 5 * np .random .randn (1000 ) + 50
25
+ result = find_anomalies_z_score (data )
26
+ print ('outliers : ' , result )
You can’t perform that action at this time.
0 commit comments