Repository navigation
Expand file tree
/
Copy pathf_statistics.py
More file actions
80 lines (61 loc) · 1.74 KB
/
Copy pathf_statistics.py
File metadata and controls
80 lines (61 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import math
def ft_count(array):
counter = 0
for element in array:
if element == element:
counter += 1
return counter
def ft_mean(array):
total: float = 0
for element in array:
if element == element:
total += element
return total / ft_count(array)
def standard_deviation(array):
count = ft_count(array)
mean = ft_mean(array)
variance = 0
deviation = 0
standard_deviation = 0
for element in array:
if element == element:
deviation += (element - mean) ** 2
variance = deviation / count
# standard_deviation = math.sqrt(variance)
standard_deviation = variance**0.5
return standard_deviation
def minimum(array):
minimum = 0
for element in array:
if element == element:
if element < minimum:
minimum = element
return minimum
def maximum(array):
maximum = 0
for element in array:
if element == element:
if element > maximum:
maximum = element
return maximum
def percentile(array, percent: float):
"""
méthode recommandée par le National Institute of Standards and Technology (NIST)
1 + P*(n-1)/100
"""
sorted_array = array.sort_values(ignore_index=True)
value = 0
count = ft_count(array)
rank = 1 + percent * (count - 1)
index = rank - 1
floor = math.floor(index)
ceil = math.ceil(index)
reste_floor = index - floor
# reste_ceil = ceil - index
floor_value = sorted_array.loc[floor]
ceil_value = sorted_array.loc[ceil]
if index - floor != 0:
value = floor_value + reste_floor * (ceil_value - floor_value)
else:
value = sorted_array.loc[index]
return value