Jovian
⭐️
Sign In
Learn data science and machine learning by building real-world projects on Jovian
In [2]:
!pip install jovian --upgrade --quiet
In [3]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline   
In [4]:
df = pd.read_csv('Iris.csv')
print (df.shape)
(150, 6)
In [5]:
df.isnull().sum() #no null values in the data set 

#removed the id column from the table 
df.drop(['Id'], axis = 1, inplace = True)
In [6]:
df.columns = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species']
df['species'] = df['species'].apply(lambda x: x.replace('Iris-', ''))
In [7]:
#how to get the unique values presnet in the columns species 
df['species'].unique()
Out[7]:
array(['setosa', 'versicolor', 'virginica'], dtype=object)
In [8]:
df_new = df.copy()
#this is how mapping can be done 
generic_mapping = {'setosa': 1, 'versicolor': 2, 'virginica': 3}
df_new['species'] = df_new['species'].map(generic_mapping)
#print (df_new['species'])
#plt.plot(df_new['sepal_length'], df_new['species'])

df.head(5)
Out[8]:

UNIVARIATE ANALYSIS

In [9]:
df_setosa = df.loc[df['species'] == 'setosa']
df_versicolor = df.loc[df['species'] == 'versicolor']
df_virginica = df.loc[df['species'] == 'virginica']

df_setosa.head(5)
Out[9]:
In [10]:
plt.plot(df_setosa['petal_length'], np.zeros_like(df_setosa['petal_length']), 'o')
plt.plot(df_versicolor['petal_length'], np.zeros_like(df_versicolor['petal_length']), '*')
plt.plot(df_virginica['petal_length'], np.zeros_like(df_virginica['petal_length']), '^')
Out[10]:
[<matplotlib.lines.Line2D at 0x7ff70cc02cd0>]
Notebook Image

BIVARIATE ANALYSIS

In [11]:
#showing the overlapping of the data acc to sepal length & sepal width 

# to check how all the features are corelated to each other 
sns.FacetGrid(df, hue = 'species', height = 8).map(plt.scatter, "sepal_length", "sepal_width").add_legend();
Notebook Image

MULTIVARIATE ANALYSIS

In [12]:
#if we have more than three features - multivariate analysis - using pair plot - give me the all possible relation for features mapping to the species 
sns.pairplot(df, hue = 'species', height  = 5)
Out[12]:
<seaborn.axisgrid.PairGrid at 0x7ff70cc121d0>
Notebook Image
In [ ]:
jovian.commit()
[jovian] Detected Colab notebook... [jovian] Please enter your API key ( from https://jovian.ai/ ): API KEY:
In [ ]: