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

Mi 2

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 DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Mi 2

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 DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Enrollment No: 202203103510381

PRACTICAL-4
Aim : Write a python program to perform multiclass classification on iris dataset.

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: 202203103510381

# 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)

# 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]


Enrollment No: 202203103510381

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

You might also like