# import
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from sklearn.datasets import load_iris
%matplotlib inline
# reading data
data = pd.DataFrame(load_iris()['data'])
target = pd.DataFrame(load_iris()['target'])
iris =pd.concat([data, target], axis=1)
iris.columns = ['sepal_length','sepal_width','petal_length','petal_width', 'species']
iris[:3]
sepal_length | sepal_width | petal_length | petal_width | species | |
---|---|---|---|---|---|
0 | 5.1 | 3.5 | 1.4 | 0.2 | 0 |
1 | 4.9 | 3.0 | 1.4 | 0.2 | 0 |
2 | 4.7 | 3.2 | 1.3 | 0.2 | 0 |
# I have already import matplotlib library (python plotting)
# now plotting the data
setosa = iris[iris['species']==0]
versi = iris[iris['species']==1]
vergi = iris[iris['species']==2]
# plotting "sepal length" and "sepal width" for
plt.scatter(setosa.iloc[:, 0], setosa.iloc[:, 1])
<matplotlib.collections.PathCollection at 0x2406703c278>
# plotting "sepal length" histogram
plt.hist(setosa.iloc[:, 0])
(array([ 4., 1., 6., 5., 12., 8., 4., 5., 2., 3.]), array([ 4.3 , 4.45, 4.6 , 4.75, 4.9 , 5.05, 5.2 , 5.35, 5.5 , 5.65, 5.8 ]), <a list of 10 Patch objects>)
plt.boxplot(setosa.iloc[:, 2])
{'boxes': [<matplotlib.lines.Line2D at 0x240697ee198>], 'caps': [<matplotlib.lines.Line2D at 0x240697f3ba8>, <matplotlib.lines.Line2D at 0x240697f3d30>], 'fliers': [<matplotlib.lines.Line2D at 0x240697f8da0>], 'means': [], 'medians': [<matplotlib.lines.Line2D at 0x240697f8588>], 'whiskers': [<matplotlib.lines.Line2D at 0x240697eeb38>, <matplotlib.lines.Line2D at 0x240697eecc0>]}
setosa.iloc[:, 0:2]
sepal_length | sepal_width | |
---|---|---|
0 | 5.1 | 3.5 |
1 | 4.9 | 3.0 |
2 | 4.7 | 3.2 |
3 | 4.6 | 3.1 |
4 | 5.0 | 3.6 |
5 | 5.4 | 3.9 |
6 | 4.6 | 3.4 |
7 | 5.0 | 3.4 |
8 | 4.4 | 2.9 |
9 | 4.9 | 3.1 |
10 | 5.4 | 3.7 |
11 | 4.8 | 3.4 |
12 | 4.8 | 3.0 |
13 | 4.3 | 3.0 |
14 | 5.8 | 4.0 |
15 | 5.7 | 4.4 |
16 | 5.4 | 3.9 |
17 | 5.1 | 3.5 |
18 | 5.7 | 3.8 |
19 | 5.1 | 3.8 |
20 | 5.4 | 3.4 |
21 | 5.1 | 3.7 |
22 | 4.6 | 3.6 |
23 | 5.1 | 3.3 |
24 | 4.8 | 3.4 |
25 | 5.0 | 3.0 |
26 | 5.0 | 3.4 |
27 | 5.2 | 3.5 |
28 | 5.2 | 3.4 |
29 | 4.7 | 3.2 |
30 | 4.8 | 3.1 |
31 | 5.4 | 3.4 |
32 | 5.2 | 4.1 |
33 | 5.5 | 4.2 |
34 | 4.9 | 3.1 |
35 | 5.0 | 3.2 |
36 | 5.5 | 3.5 |
37 | 4.9 | 3.1 |
38 | 4.4 | 3.0 |
39 | 5.1 | 3.4 |
40 | 5.0 | 3.5 |
41 | 4.5 | 2.3 |
42 | 4.4 | 3.2 |
43 | 5.0 | 3.5 |
44 | 5.1 | 3.8 |
45 | 4.8 | 3.0 |
46 | 5.1 | 3.8 |
47 | 4.6 | 3.2 |
48 | 5.3 | 3.7 |
49 | 5.0 | 3.3 |