0% found this document useful (0 votes)
4 views5 pages

ML Lab - 3

This is ML lab experiment

Uploaded by

Sindhu Dhavanam
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)
4 views5 pages

ML Lab - 3

This is ML lab experiment

Uploaded by

Sindhu Dhavanam
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/ 5

Roll No: 160621733015 Experiment No: 03

Name: Dhavanam Sindhu Date: 12/08/2024

AIM: K-Nearest Neighbors Classifier


K-Nearest Neighbors (KNN) Classifier is a simple, non-parametric algorithm used for
classification and regression tasks. It classifies a data point based on the majority class among
its 'k' closest data points in the feature space, which are determined using a distance metric
(such as Euclidean distance).
KNN is intuitive and effective for smaller datasets but can be computationally
expensive and less accurate with large datasets or when the data has many irrelevant features.

STEPS:
1. Create Own Dataset:
 In this step, we define the data that we want to analyze. This involves selecting
the features (e.g., height, weight) and the target variable (e.g., classifying
individuals as "fit" or "unfit").
 Here we manually create a small dataset with sample data points to be used in
your machine learning model.
data = { 'Height': [150, 160, 170, 180, 190, 200],
'Weight': [50, 60, 70, 80, 90, 100],
'Class': ['fit', 'fit', 'fit', 'unfit', 'unfit', 'unfit']
}

Department of CSE, Stanley College of Engineering and Technology for Women


Roll No: 160621733015 Experiment No: 03

Name: Dhavanam Sindhu Date: 12/08/2024

2. Load the Dataset:

 After creating the dataset, you need to load it into your Python environment.
This is typically done using a library like Pandas, which allows you to read the
dataset from various formats such as CSV files.
 Example: We loaded the dataset from a CSV file using
pd.read_csv('fitness_data.csv').

3. Display the Dataset:

 Once the dataset is loaded, it's important to inspect it to understand its structure
and contents. Displaying the dataset allows you to verify that the data has been
loaded correctly and helps you to identify any issues such as missing values or
incorrect data types.
 Example: We used df.head() to display the first few rows of the dataset, giving us
a quick overview of the data.

Department of CSE, Stanley College of Engineering and Technology for Women


Roll No: 160621733015 Experiment No: 03

Name: Dhavanam Sindhu Date: 12/08/2024

4. Pre-process the Dataset:

 Preprocessing involves cleaning and preparing the dataset for analysis or


model training.
 This can include tasks like handling missing values, normalizing numerical
features, and encoding categorical variables. The goal is to clean and
transform the data into a format that can be effectively used by the machine
learning algorithm.
 Example: We encoded the categorical "Class" column (fit/unfit) into
numerical values using LabelEncoder, converting it into a form that the KNN
classifier can use.

Department of CSE, Stanley College of Engineering and Technology for Women


Roll No: 160621733015 Experiment No: 03

Name: Dhavanam Sindhu Date: 12/08/2024

5. Apply KNN Classifier:

 In this step, we use the K-Nearest Neighbours (KNN) algorithm to build a


classification model.
 This involves splitting the dataset into features (inputs) and labels (outputs),
training the KNN model on the training data, and then testing its performance
on the test data. The accuracy of the model is evaluated based on how well it
predicts the labels for the test set.
 Example: We split the data into training and testing sets, trained the KNN
classifier on the training data, and then evaluated its accuracy using the
accuracy_score function.

Department of CSE, Stanley College of Engineering and Technology for Women


Roll No: 160621733015 Experiment No: 03

Name: Dhavanam Sindhu Date: 12/08/2024

Department of CSE, Stanley College of Engineering and Technology for Women

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy