0% found this document useful (0 votes)
10 views

Iris - Ipynb - Colaboratory

iris collab

Uploaded by

harsharover2002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Iris - Ipynb - Colaboratory

iris collab

Uploaded by

harsharover2002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

from IPython.

display import Image


Image(filename='/content/iris1.jpg', width=500)

from IPython.display import Image


Image(filename='/content/iris2.jpg', width=500)
from IPython.display import Image
Image(filename='/content/iris3.jpg', width=500)

import warnings
warnings.filterwarnings('ignore')
from sklearn import datasets
import numpy as np
df = datasets.load_iris()

import pandas as pd

# Reading the CSV file


df = pd.read_csv("/content/iris.csv")

# Printing top 5 rows


df.head()

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


df.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

corr = df.corr()
print(corr)

Sepal.Length Sepal.Width Petal.Length Petal.Width


Sepal.Length 1.000000 -0.117570 0.871754 0.817941
Sepal.Width -0.117570 1.000000 -0.428440 -0.366126
Petal.Length 0.871754 -0.428440 1.000000 0.962865
Petal.Width 0.817941 -0.366126 0.962865 1.000000

import statsmodels.api as sm
sm.graphics.plot_corr(corr, xnames=list(corr.columns))
plt.show()

df.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
df.isnull().sum() 7.900000 4.400000 6.900000 2.500000

Sepal.Length 0
Sepal.Width 0
Petal.Length 0
Petal.Width 0
Species 0
dtype: int64

import warnings
warnings.filterwarnings('ignore')

from sklearn import datasets


import numpy as np

iris = datasets.load_iris()

import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

# Let's convert to dataframe


iris = pd.DataFrame(data= np.c_[iris['data'], iris['target']],
columns= iris['feature_names'] + ['species'])

# let's remove spaces from column name


iris.columns = iris.columns.str.replace(' ','')

# replace the values with class labels


iris.species = np.where(iris.species == 0.0, 'setosa', np.where(iris.species==1.0,'vers

# data dimension
print(iris.shape)

# Peek at the 1st few records


iris.head()
(150, 5)
sepallength(cm) sepalwidth(cm) petallength(cm) petalwidth(cm) 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


iris.describe()
4 5.0 3.6 1.4 0.2 setosa

sepallength(cm) sepalwidth(cm) petallength(cm) petalwidth(cm)

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

print(iris['species'].value_counts())

versicolor 50
setosa 50
virginica 50
Name: species, dtype: int64

# Set the size of the plot


plt.figure(figsize=(15,8))

iris.hist() # plot histogram


plt.suptitle("Histogram", fontsize=12) # use suptitle to add title to all sublots
plt.tight_layout(pad=1)
plt.show()

iris.boxplot() # plot boxplot


plt.title("Bar Plot", fontsize=16)
plt.tight_layout(pad=1)
plt.show()
<Figure size 1080x576 with 0 Axes>

corr = iris.corr()
print(corr)

sepallength(cm) ... petalwidth(cm)


sepallength(cm) 1.000000 ... 0.817941
sepalwidth(cm) -0.117570 ... -0.366126
petallength(cm) 0.871754 ... 0.962865
petalwidth(cm) 0.817941 ... 1.000000

[4 rows x 4 columns]

import statsmodels.api as sm
sm.graphics.plot_corr(corr, xnames=list(corr.columns))
plt.show()
import pandas as pd
from pandas.plotting import scatter_matrix
scatter_matrix(iris, figsize=(10, 10))
plt.suptitle("Pair Plot", fontsize=20) # use suptitle to add title to all sublots

Text(0.5, 0.98, 'Pair Plot')

You might also like