Skip to content

Commit cd0ef9e

Browse files
committed
update
1 parent 6c30b71 commit cd0ef9e

File tree

1 file changed

+49
-6
lines changed

1 file changed

+49
-6
lines changed

Statistical-Python/StatsAss1.py

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,53 @@
11
import matplotlib
2-
import nump
2+
import numpy
3+
import math
4+
from scipy import stats
35

4-
def getData():
5-
pass
6-
def displayGraph():
7-
pass
6+
def populationVariance(n):
7+
mean = sum(n)/len(n)
8+
n_sum = 0
9+
for i in n:
10+
n_sum += (i - mean)**2
11+
12+
return n_sum / len(n)
13+
def sampleVariance(n):
14+
mean = sum(n)/len(n)
15+
n_sum = 0
16+
for i in n:
17+
n_sum += (i - mean)**2
818

19+
return n_sum / (len(n) - 1)
20+
21+
def getData(n):
22+
23+
print(f"Mean: {sum(n)/len(n)}")
24+
if len(n) % 2 == 0:
25+
print(f"Median: {n[int(len(n)/2-1)] + n[int(len(n)/2) - 1]}")
26+
else:
27+
print(f"Median: {n[int((len(n)/2)-1) - 1]}")
28+
29+
res = stats.mode(n)
30+
print(f"Mode: {res.mode, res.count}")
31+
print(f"Min: {min(n)}")
32+
print(f"Max: {max(n)}")
33+
print(f"Range: {max(n) - min(n)}")
34+
print(f"IQR: {numpy.percentile(n, 75) - numpy.percentile(n, 25)}")
35+
print(f"Population Variance: {round(populationVariance(n), 4)}")
36+
print(f"Sample Variance: {round(sampleVariance(n), 4)}")
37+
print(f"Population Standard Deviation: {round(math.sqrt(populationVariance(n)), 4)}")
38+
print(f"Sample Standard Deviation: {round(math.sqrt(sampleVariance(n)), 4)}")
39+
print(f"Coefficient of Variation: {round((sampleVariance(n) / (sum(n)/len(n))) * 100, 4)}")
40+
print(f"76th percentile: {n[int((76 * (len(n) + 1)) / 100) - 1]}")
41+
print(f"85th percentile: {n[int((85 * (len(n) + 1)) / 100) - 1]}")
42+
print(f"6th decile: {n[int((6 * (len(n) + 1)) / 100) - 1]}")
43+
44+
945
def main():
10-
getData(); # get Data from excel file
46+
n = input("INPUT: ").split(" ")
47+
print(len(n))
48+
n = [int(i) for i in n]
49+
print(sorted(n))
50+
getData(n)
51+
52+
53+
main()

0 commit comments

Comments
 (0)