AI LAB Assignment 09
AI LAB Assignment 09
PRN: 21070122209
Batch: TYCS AI4
Assignment 9
Aim: Apply the K-Nearest Neighbours classifier algorithm on a sample case
study and data set and evaluate results.
Objective: The objective of the provided code is to build a classification model
using the K-Nearest Neighbors (KNN) algorithm to predict the class of
shipping e-commerce orders based on various features.
Algorithm:
1. Data Loading: Load the shipping ecommerce dataset from a CSV file.
2. Data Preprocessing:
Encode categorical variables: Convert categorical variables like
'Warehouse_block', 'Mode_of_Shipment', 'Product_importance',
and 'Gender' into numerical format using label encoding.
3. Data Splitting: Split the dataset into features (X) and the target
variable (y), which represents the class labels.
4. Feature Scaling: Scale the features using StandardScaler to
standardize them.
5. Model Training: Train a KNN classifier using the training data to
learn patterns in the features and their corresponding class labels.
6. Model Evaluation: Evaluate the trained model's performance on the
test dataset by predicting the class labels and computing metrics such
as accuracy and classification report.
7. Output: Print the accuracy and classification report to assess the
model's performance.
Input:
Output: