-
Notifications
You must be signed in to change notification settings - Fork 0
/
Iris Classification.py
137 lines (60 loc) · 1.6 KB
/
Iris Classification.py
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
#!/usr/bin/env python
# coding: utf-8
# In[7]:
import sklearn
import numpy
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
# In[8]:
df = pd.read_csv("C:/Users/Shreya Ladhane/OneDrive/Desktop/Python p/Iris.csv")
df.tail()
# In[9]:
df = df.drop(columns=["Id"])
# In[10]:
#Display basic statistics about the data
df.describe().transpose()
# In[11]:
#checking for null values
df.isnull().sum()
# In[12]:
print('Shape of the dataset : ',df.shape)
# In[13]:
df.info()
# In[14]:
# Display the number of samples for each class
df['Species'].value_counts()
# In[15]:
#Label encoding to convert class labels into numeric form
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
df['Species'] = le.fit_transform(df['Species'])
df['Species']
# In[16]:
df
# In[17]:
sns.countplot(x='Species',data=df,palette=['yellow','red','green'])
# In[19]:
#analysing distribution of columns values
sns.swarmplot(x=df['Species'],y=df['SepalLengthCm'],color='red')
# In[20]:
sns.swarmplot(x=df['Species'],y=df['SepalWidthCm'],color='green')
# In[21]:
sns.swarmplot(x=df['Species'],y=df['PetalLengthCm'],color='y')
# In[22]:
sns.swarmplot(x=df['Species'],y=df['PetalWidthCm'],color='orange')
# In[23]:
#Plotting the histogram of all features toghether
df['SepalLengthCm'].hist()
df['SepalWidthCm'].hist()
df['PetalLengthCm'].hist()
df['PetalWidthCm'].hist()
# In[24]:
sns.pairplot(df,hue='Species')
# In[25]:
# Compute the correlation matrix
df.corr().transpose()
# In[ ]: