Skip to content

Commit 3df7f08

Browse files
authored
Update Irist_scanner.py
1 parent 1e995d2 commit 3df7f08

File tree

1 file changed

+20
-68
lines changed

1 file changed

+20
-68
lines changed

IrisFlowerClassification Using Machine Learning/Irist_scanner.py

Lines changed: 20 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import seaborn as sns
66
import warnings
77
from numpy.conftest import dtype
8+
from sklearn.linear_model import LogisticRegression
9+
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report
810

11+
model = LogisticRegression()
912
warnings.simplefilter("ignore")
1013

1114

@@ -42,13 +45,6 @@
4245
plt.title("Correlation Matrix")
4346
plt.show()
4447

45-
#Box Plot for Outlier
46-
for col in ['SepalLength', 'SepalWidth','PetalLength','PetalWidth']:
47-
sns.boxplot(df[col])
48-
plt.title(f'Box plot of {col}')
49-
plt.show()
50-
51-
5248
#Define x and y
5349

5450
x=df[['SepalLength', 'SepalWidth','PetalWidth','PetalLength']] #Independent Variables
@@ -66,73 +62,29 @@
6662
print("Y_test shape:", y_test.shape)
6763

6864

69-
print(df.describe())
70-
from email.errors import FirstHeaderLineIsContinuationDefect
71-
import pandas as pd
72-
import numpy as np
73-
import matplotlib.pyplot as plt
74-
import seaborn as sns
75-
import warnings
76-
from numpy.conftest import dtype
77-
78-
warnings.simplefilter("ignore")
65+
model.fit(x_train,y_train)
66+
y_pred=model.predict(x_test)
7967

80-
81-
#Import iris Dataset.
82-
df=pd.read_csv(r'C:\Users\PC\Downloads\iris\iris.data')
68+
#calculate accuracy and confusion matrix
69+
accuracy = accuracy_score(y_test,y_pred)*100
70+
conf_matrix = confusion_matrix(y_test,y_pred)
8371

8472

85-
# Assign column names to the dataset
86-
df.columns = ['SepalLength', 'SepalWidth', 'PetalLength','PetalWidth', 'Species']
87-
88-
# Dataset Info
89-
df.info()
90-
91-
# Checking for null values
92-
print(df.isnull().sum())
93-
94-
# Display column names
95-
print(df.columns)
96-
97-
#Value counts for Species column
98-
print("Unique Species:", df['Species'].unique())
99-
print("Duplicate Rows:", df.duplicated().sum())
73+
print("Accuracy of the model is {:.2f}%".format(accuracy))
74+
print("Confusion Matrix: ")
75+
print(conf_matrix)
10076

101-
#Visualize the species count
102-
sns.pairplot(df,hue='Species', palette='husl')
103-
sns.set(style="whitegrid") #seaborn style
104-
plt.title("Pair Plot of Iris DataSet")
105-
plt.show()
77+
#print Classification report
78+
print("\nClassification Report:")
79+
print(classification_report(y_test, y_pred))
10680

81+
#visualize confusion report
10782

108-
#Heatmaps
109-
plt.figure(figsize=(10,6))
110-
sns.heatmap(df.drop('Species', axis=1).corr(),annot=True,cmap='coolwarm')
111-
plt.title("Correlation Matrix")
83+
plt.figure(figsize=(8,6))
84+
sns.heatmap(conf_matrix, annot=True, fmt='d', cmap='Blues', xticklabels=model.classes_,yticklabels=model.classes_)
85+
plt.xlabel('Predicted Labels')
86+
plt.ylabel('True Lables')
87+
plt.title('Confusion Matrix')
11288
plt.show()
11389

114-
#Box Plot for Outlier
115-
for col in ['SepalLength', 'SepalWidth','PetalLength','PetalWidth']:
116-
sns.boxplot(df[col])
117-
plt.title(f'Box plot of {col}')
118-
plt.show()
119-
120-
121-
#Define x and y
122-
123-
x=df[['SepalLength', 'SepalWidth','PetalWidth','PetalLength']] #Independent Variables
124-
y=df['Species'] #Dependent Variable
125-
126-
# Split the dataset into training and testing sets
127-
from sklearn.model_selection import train_test_split
128-
x_train, x_test, y_train, y_test=train_test_split (x,y,random_state=0, test_size=0.2) #20% Test Set
129-
130-
#Check Shapes
131-
132-
print("X_train shape:", x_train.shape)
133-
print("X_test shape:", x_test.shape)
134-
print("Y_train shape:", y_train.shape)
135-
print("Y_test shape:", y_test.shape)
136-
137-
13890
print(df.describe())

0 commit comments

Comments
 (0)