You are on page 1of 2

Aim: CLASSIFICATION MODEL: a. Install relevant package for classification.

b. Choose classifier for classification problem.


c. Evaluate the performance of classifier.
Code:
# Step a: Install scikit-learn package

# You can install scikit-learn using pip if you haven't already installed it

# pip install scikit-learn

import pandas as pd

from sklearn.model_selection import train_test_split

from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import accuracy_score, classification_report, confusion_matrix

# Load the dataset (example using Iris dataset)

from sklearn.datasets import load_iris

iris = load_iris()

X = iris.data

y = iris.target

# Step b: Choose a classifier (example using Random Forest)

classifier = RandomForestClassifier()

# Split the data into training and testing sets

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

# Train the classifier on the training data

classifier.fit(X_train, y_train)

# Make predictions on the testing data

y_pred = classifier.predict(X_test)
# Step c: Evaluate the performance of the classifier

accuracy = accuracy_score(y_test, y_pred)

print("Accuracy:", accuracy)

# Other evaluation metrics

print("Classification Report:")

print(classification_report(y_test, y_pred))

print("Confusion Matrix:")

print(confusion_matrix(y_test, y_pred))

You might also like