Pages

Friday, November 24, 2017

Analysis of Iris data

Iris_analysis

Analysis of Iris dataset

Using Notebook, let us try to dig deep in this Iris dataset.

In [19]:
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline 
import seaborn as sns
import numpy as np
import pandas as pd

iris = sns.load_dataset("iris")
In [20]:
#Print shape of the data
print (iris.shape)
(150, 5)
In [21]:
#print top few rows
print(iris.head(5))
   sepal_length  sepal_width  petal_length  petal_width species
0           5.1          3.5           1.4          0.2  setosa
1           4.9          3.0           1.4          0.2  setosa
2           4.7          3.2           1.3          0.2  setosa
3           4.6          3.1           1.5          0.2  setosa
4           5.0          3.6           1.4          0.2  setosa
In [22]:
#summary of iris data
print (iris.describe())
       sepal_length  sepal_width  petal_length  petal_width
count    150.000000   150.000000    150.000000   150.000000
mean       5.843333     3.057333      3.758000     1.199333
std        0.828066     0.435866      1.765298     0.762238
min        4.300000     2.000000      1.000000     0.100000
25%        5.100000     2.800000      1.600000     0.300000
50%        5.800000     3.000000      4.350000     1.300000
75%        6.400000     3.300000      5.100000     1.800000
max        7.900000     4.400000      6.900000     2.500000
In [23]:
#print counts of each species
print (iris["species"].value_counts())
setosa        50
versicolor    50
virginica     50
Name: species, dtype: int64
In [24]:
# Swarmplots to understand the distribution
plt.subplots_adjust(hspace=.5,wspace = 0.2)
plt.subplot(221)
sns.swarmplot(x="species", y="sepal_length", data=iris);
plt.subplot(222)
sns.swarmplot(x="species", y="sepal_width", data=iris);
plt.subplot(223)
sns.swarmplot(x="species", y="petal_length", data=iris);
plt.subplot(224)
sns.swarmplot(x="species", y="petal_width", data=iris);
plt.show()
In [25]:
# Pair plot of iris features of Regression kind to identify relationships
plt.clf()
sns.pairplot(iris, hue="species", size=3, kind="reg")
plt.show()
<matplotlib.figure.Figure at 0x7eff68af6f60>

No comments:

Post a Comment

SVM on Iris Data - Part 1

iris_svm_1 In [49]: import matplotlib import matplotlib.pyplot as plt % matplot...