Python Numpy, detect abnormals values in a list -
this question has answer here:
in list, d'like reject values because deviates median : 0.4877, 0.5113 , 1.5103
i did following code , seems work d'like know if right way ? data_std = 0.30988 seems lot. shoud use squared root ?
import numpy def out_of_range(d, min, max): if d < min or d > max: return " " #rejected return "" data = list([0.1410, 0.1437, 0.1371, 0.1318, 0.4877, 0.5113, 1.5103, 0.1388, 0.1398, 0.1384, 0.1406, 0.1383, 0.1458, 0.1410, 0.1423, 0.1372, 0.1386, 0.1343, 0.1397, 0.1413]) data_mean = numpy.mean(data) data_std = numpy.std(data) data_median = numpy.median(data) min_range = data_median - data_std max_range = data_median + data_std print "mean : " + str(data_mean) print "median : " + str(data_median) print "std dev : " + str(data_std) print "min_range : " + str(min_range) print "max_range : " + str(max_range) print "" print "---data---" d in data: print out_of_range(d, min_range, max_range) +str(d)
returns
mean : 0.24395 median : 0.1402 std dev : 0.309883094892 min_range : -0.169683094892 max_range : 0.450083094892 ---data--- 0.141 0.1437 0.1371 0.1318 0.4877 0.5113 1.5103 0.1388 0.1398 0.1384 0.1406 0.1383 0.1458 0.141 0.1423 0.1372 0.1386 0.1343 0.1397 0.1413
the number correct.
(sum( (i-np.mean(data))**2 in data )/len(data))**0.5 0.30988309489225124 np.std(data) 0.30988309489225124
Comments
Post a Comment