-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatasets.py
91 lines (67 loc) · 1.94 KB
/
datasets.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import math
def inputFunction():
dataset=input("Please enter a set of numbers:")
return dataset
def maxFunction(dataSet):
return max(dataSet)
def minFunction(dataSet):
return min(dataSet)
def meanFunction(dataSet):
total=sum(dataSet)
count=len(dataSet)
mean=total*1.0/float(count)
return mean
def stdevFunction(dataset):
meanval=meanFunction(dataset)
total=0
for number in dataset:
difference=meanval-number
square=difference**2
total=total+square
n=len(dataset)-1
variation=total/(n)
result=math.sqrt(variation)
return result
def medianFunction(dataset):
newset=sorted(dataset)
count=len(newset)
middle=count/2
result=newset[middle]
return result
def modeFunction(dataset):
listValues=[]
listCounts=[]
for number in dataset:
if number in listValues:
cindex=listValues.index(number)
listCounts[cindex]=listCounts[cindex]+1
else:
listValues.append(number)
listCounts.append(1)
maxval=maxFunction(listCounts)
maxindex=listCounts.index(maxval)
result=listValues[maxindex]
return result
def outputFunction (dataset,minval,maxval,meanval,medianval,modeval,stdVal):
print dataset
print "Min : %3.2f"%minval
print "Max : %3.2f"%maxval
print "Mean : %3.2f"%meanval
print "Median: %3.2f"%medianval
print "Mode : %3.2f"%modeval
print "Stdev : %3.2f"% stdVal
dataset=inputFunction()
print dataset
minval=minFunction(dataset)
print minval
maxval=maxFunction(dataset)
print maxval
meanval=meanFunction(dataset)
print meanval
stdVal=stdevFunction(dataset)
print stdVal
medianval=medianFunction(dataset)
print medianval
modeval=modeFunction(dataset)
print modeval
outputFunction (dataset,minval,maxval,meanval,medianval,modeval,stdVal)