-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrowd Computing.py
121 lines (71 loc) · 2.55 KB
/
Crowd Computing.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python
# coding: utf-8
# In[9]:
cc=[34,67,54,84,23,19]
cc.sort()
for i in range(len(cc)):
print(cc[i])
# In[14]:
from statistics import mean # this a one method to do so,
cc=[34,67,54,84,23,19]
cc.sort()
trimmedvalue=int(0.1*len(cc)) #this was taking 10% of the actual crowd.
cc=cc[trimmedvalue:] #upper 10% trimming.
cc=cc[:len(cc)-trimmedvalue] #lower 10% trimming.
print(mean(cc)) #printing the mean of the trimmed list of crowd.
# In[21]:
# this a second method to do so using SCIPY library
from scipy import stats
cc=[34,67,54,84,23,19]
cc.sort()
m=stats.trim_mean(cc,0.1)
print(m)
# In[2]:
import matplotlib.pyplot as plt
plt.plot([2,6,4,5]) # remember python automatically generates x values if we don't pass any.
# In[3]:
import matplotlib.pyplot as plt
plt.plot([2,3,4,5],[3,1,7,2]) #now this will be treated as (x,y) co-ordinates.
plt.ylabel("this is y coordinate") #this will label the y coordinate
plt.xlabel("this is x coordinate")
# In[4]:
# plotting in form of dots
import matplotlib.pyplot as plt
plt.plot([2,3,4,5],[3,1,7,2],'ro')
# In[5]:
#plotting in form of ----
import matplotlib.pyplot as plt
plt.plot([2,3,4,5],[3,1,7,2],'r--')
# In[6]:
#plotting in form of blue squares
import matplotlib.pyplot as plt
plt.plot([2,3,4,5],[3,1,7,2],'bs')
# In[7]:
#plotting in form of green traingles
import matplotlib.pyplot as plt
plt.plot([2,3,4,5],[3,1,7,2],'g^')
# In[8]:
#ploting the crowd data list.
import matplotlib.pyplot as plt
cc=[34,67,54,23,3,56,88]
plt.plot(cc)
# In[9]:
# now let us represent data on a constant y =5 with mean and median
import statistics
import matplotlib.pyplot as plt
cc=[34,67,54,23,3,56,88]
y=[] # created an array
cc.sort()
trimmedvalue=int(0.1*(len(cc))) # trimming 10% to get closer results.
cc=cc[trimmedvalue:]
cc=cc[:len(cc)-trimmedvalue]
for i in range(len(cc)):
y.append(5) # append any constant value. this will just get the data in x scale and represented as a line.
plt.plot(cc,y)
plt.plot([statistics.mean(cc)],[5],'ro') # hence we import statistics(to get mean and median)library to do this.
plt.plot([statistics.median(cc)],[5],'bs')
plt.plot([49], [5], 'g^')
# what is shown here is that we had a list of data(collected from crowd of any entity) the actual answer was 49. but the people
# guessed it and we obtained a list of those data, now this is ploting of the same data i.e, the mean value is so close to
# to the actual answer, this is crowd computing.
# In[ ]: