-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
48 lines (31 loc) · 828 Bytes
/
utils.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
import math
def mean(arr: list[int]):
sum: int = 0
for n in arr:
sum += n
return sum / len(arr)
def median(arr: list[int]):
arr.sort()
return arr[int(len(arr) / 2)]
def mode(arr: list[int]):
dic = {}
n: int = 0
for i in arr:
if not i in dic:
dic[i] = 1
else:
dic[i] += 1
for g, j in dic.items():
if j == max(dic.values()):
n = g;
return n
def standard_derivation(arr: list[int]):
m: int = mean(arr)
sum: int = 0
for i in arr:
sum += (i - m)**2
return math.sqrt(sum / len(arr))
def percentile(arr: list[int], perc: int):
return sorted(arr)[int(math.ceil((len(arr) * perc) / 100)) - 1]
def estimate_price(x: int, theta0: float, theta1: float):
return theta0 + (theta1 * x)