0% found this document useful (0 votes)
1 views3 pages

Practical-4: Write A Python Program To Perform Multiclass Classification On Iris Dataset

Uploaded by

N Thakore
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)
1 views3 pages

Practical-4: Write A Python Program To Perform Multiclass Classification On Iris Dataset

Uploaded by

N Thakore
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/ 3

Enrollment No: 202203103510380

PRACTICAL-4
Aim : Write a python program to perform multiclass classification on iris dataset.
Below are the Important Steps required for any classification Process:
1. Understand the Problem
2. Collect and Prepare the Data
3. Preprocess the Data
4. Split the Dataset
5. Choose a Classification Algorithm
6. Train the Model
7. Evaluate the Model
8. Optimize the Model
9. Deploy the Model
10. Monitor and Maintain

Code :
# Import necessary libraries
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import classification_report, accuracy_score

# Load the Iris dataset


iris = load_iris()
X, y = iris.data, iris.target

UTU/CGPIT/CE/SEM-6/MACHINE INTELLIGENCE [CE5008]


Enrollment No: 202203103510380

# Split the dataset into training and testing sets

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42, stratify=y)

# Create and train the k-NN classifier

k = 3 # You can adjust the number of neighbors


knn = KNeighborsClassifier(n_neighbors=k)
knn.fit(X_train, y_train)

# Make predictions
y_pred = knn.predict(X_test)

UTU/CGPIT/CE/SEM-6/MACHINE INTELLIGENCE [CE5008]


Enrollment No: 202203103510380

# Evaluate the model


print("Classification Report:")
print(classification_report(y_test, y_pred))
print(f"Accuracy: {accuracy_score(y_test, y_pred):.2f}")

UTU/CGPIT/CE/SEM-6/MACHINE INTELLIGENCE [CE5008]

You might also like