-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDescriptive_Statistics.py
67 lines (56 loc) · 1.83 KB
/
Descriptive_Statistics.py
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
class stat:
def __init__(self, lst = []):
self.lst = lst
def count(self):
return len(self.lst)
def summmation(self):
s = 0
for i in self.lst:
s += i
return s
def Min(self):
return min(self.lst)
def Max(self):
return max(self.lst)
def Range(self):
return max(self.lst) - min(self.lst)
def Mean(self):
summation = 0
n = len(self.lst)
for j in self.lst:
summation += j
return summation // n
def Median(self):
lst_sorted = sorted(self.lst)
lst_len = len(self.lst)
if lst_len % 2 == 0:
return (lst_sorted[(lst_len - 1) //2] + lst_sorted[(lst_len + 1) // 2]) // 2
else:
return lst_sorted[(lst_len - 1) // 2]
def Mode(self):
f = {}
for k in self.lst:
if k not in f:
f[k] = 1
else:
f[k] += 1
return [m for m, l in f.items() if l == max(f.values())]
def Variance(self):
y = 0
lst_len = len(self.lst)
for w in self.lst:
y += w
avg = y // lst_len
var = sum((w - avg)**2 for w in self.lst) // lst_len
return var
def StandartDeviation(self):
y = 0
lst_len = len(self.lst)
for w in self.lst:
y += w
avg = y // lst_len
var = sum((w - avg)**2 for w in self.lst) // lst_len
std = var ** 0.5
return std
def descriptives(self):
return f'Count: {self.count()}, Sum: {self.summmation()}, Max: {self.Max()}, Min: {self.Min()}, Range: {self.Range()}, Mean: {self.Mean()}, Median: {self.Median()}, Mode: {self.Mode()}, Variance: {self.Variance()}, Standart Deviation: {self.StandartDeviation()}'