-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiris_analytics.py
More file actions
250 lines (135 loc) · 4.76 KB
/
iris_analytics.py
File metadata and controls
250 lines (135 loc) · 4.76 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/usr/bin/env python
# coding: utf-8
# # a) Tabela descritiva para cada espécie
# In[6]:
import pandas as pd
df = pd.read_csv('iris3.csv')
# In[7]:
df[["Sepal.Length", "Sepal.Width","Petal.Length","Petal.Width"]] = df[["Sepal.Length", "Sepal.Width","Petal.Length","Petal.Width"]].apply(pd.to_numeric)
# In[8]:
df.groupby('Species')['Sepal.Width',].describe()
# In[9]:
df.groupby('Species')['Sepal.Length',].describe()
# In[10]:
df.groupby('Species')['Petal.Width',].describe()
# In[11]:
df.groupby('Species')['Petal.Length',].describe()
# # b) Gráficos para cada uma das medições realizadas para a média
# In[12]:
mediaPetalLength = df.groupby('Species')['Petal.Length',].mean()
mediaPetalWidth = df.groupby('Species')['Petal.Width',].mean()
mediaSepalWidth = df.groupby('Species')['Sepal.Width',].mean()
mediaSepalLength = df.groupby('Species')['Sepal.Length',].mean()
# In[13]:
import matplotlib.pyplot as plt
x = df['Species'].unique()
y = mediaPetalLength['Petal.Length']
plt.bar(x,y)
plt.grid(True)
plt.ylabel('Média do comprimento da Pétala')
plt.xlabel("Plantas")
# In[14]:
x = df['Species'].unique()
y = mediaPetalWidth['Petal.Width']
plt.bar(x,y)
plt.grid(True)
plt.ylabel('Média da largura da Pétala ')
plt.xlabel("Plantas")
# In[15]:
x = df['Species'].unique()
y = mediaSepalWidth['Sepal.Width']
plt.bar(x,y)
plt.grid(True)
plt.ylabel('Média da largura da Sépala ')
plt.xlabel("Plantas")
# In[16]:
x = df['Species'].unique()
y = mediaSepalLength['Sepal.Length']
plt.bar(x,y)
plt.grid(True)
plt.ylabel('Média do comprimento da Sépala ')
plt.xlabel("Plantas")
# # c) Gráfico para avaliação de associação entre as variáveios comprimento e largura
#
# In[17]:
import matplotlib.pyplot as plt
import numpy as np
from sklearn import datasets
# import some data to play with
iris = datasets.load_iris()
X = iris.data[:,2 :4] # we only take the last two features.
y = iris.target
splits = np.array_split(X, 3)
setosa = splits[0]
versicolor = splits[1]
virginica = splits[2]
plt.figure(2, figsize=(8, 6)) #aumentar o tamanho do gráfico
plt.clf()
# Plot the training points
plt.scatter(setosa[:, 0], setosa[:, 1], cmap=plt.cm.Set1, edgecolor="black", color="red")
plt.xlabel("Petal length")
plt.ylabel("Petal width")
plt.show()
#calculando a correlação de pearson
from scipy.stats import pearsonr
print("A relação entre as variáveis largura e comprimento da setosa usando a correlação de Pearson é: ", pearsonr(setosa[:, 0], setosa[:, 1])[0])
# In[18]:
# import some data to play with
iris = datasets.load_iris()
X = iris.data[:,2 :4] # we only take the last two features.
y = iris.target
splits = np.array_split(X, 3)
setosa = splits[0]
versicolor = splits[1]
virginica = splits[2]
plt.figure(2, figsize=(8, 6)) #aumentar o tamanho do gráfico
plt.clf()
# Plot the training points
plt.scatter(versicolor[:, 0], versicolor[:, 1], cmap=plt.cm.Set1, edgecolor="black", color="orange")
plt.xlabel("Petal length")
plt.ylabel("Petal width")
plt.show()
#calculando a correlação de pearson
from scipy.stats import pearsonr
print("A relação entre as variáveis largura e comprimento da versicolor usando a correlação de Pearson é: ", pearsonr(versicolor[:, 0], versicolor[:, 1])[0])
# In[19]:
# import some data to play with
iris = datasets.load_iris()
X = iris.data[:,2 :4] # we only take the last two features.
y = iris.target
splits = np.array_split(X, 3)
setosa = splits[0]
versicolor = splits[1]
virginica = splits[2]
plt.figure(2, figsize=(8, 6)) #aumentar o tamanho do gráfico
plt.clf()
# Plot the training points
plt.scatter(virginica[:, 0], virginica[:, 1], cmap=plt.cm.Set1, edgecolor="black", color="grey")
plt.xlabel("Petal length")
plt.ylabel("Petal width")
plt.show()
#calculando a correlação de pearson
from scipy.stats import pearsonr
print("A relação entre as variáveis largura e comprimento da virginica usando a correlação de Pearson é: ", pearsonr(virginica[:, 0], virginica[:, 1])[0])
# In[21]:
# import some data to play with
iris = datasets.load_iris()
X = iris.data[:,2 :4] # we only take the last two features.
y = iris.target
splits = np.array_split(X, 3)
setosa = splits[0]
versicolor = splits[1]
virginica = splits[2]
plt.figure(2, figsize=(8, 6)) #aumentar o tamanho do gráfico
plt.clf()
# Plot the training points
colors = plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Set1, edgecolor="k")
plt.xlabel("Petal length")
plt.ylabel("Petal width")
classes = ['Setosa', 'Versicolor', 'Sirginica']
plt.legend(handles=colors.legend_elements()[0], labels=classes)
plt.show()
#calculando a correlação de pearson
from scipy.stats import pearsonr
print("A relação entre as variáveis largura e comprimento de todas usando a correlação de Pearson é: ", pearsonr(X[:, 0], X[:, 1])[0])
# In[ ]: