Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Applied Machine Learning (3171617)

Experiment No 6: K-NN classifier

Date:
Competency and Practical Skills:
Relevant CO: 3, 5
Objectives:
1. To understand how KNN works.
2. To split dataset in Train/Test.
3. To learn to train classifier

Implementation:
1. Implement a KNN classifier using the scikit-learn library.
2. Train the model using a binary classification dataset of your choice.
3. Evaluate the performance of the model using metrics such as accuracy, precision, recall, and
F1-score.

Source Code:

Output:
Applied Machine Learning (3171617)

Conclusion:
The K-Nearest Neighbors (KNN) classifier was implemented using sci-kit-learn, and its performance
was evaluated on a binary classification dataset, achieving satisfactory accuracy, precision, recall, and
F1 score metrics.

Related Questions:
1. What are some common performance metrics used to evaluate the accuracy of a KNN classifier, and
how do you interpret them?
◈ accuracy is a basic metric for assessing KNN classifier performance, it may not be sufficient in all
cases, especially when dealing with imbalanced datasets. Precision, recall, and the F1-score
provide a more detailed evaluation, helping to understand how well the classifier performs in
correctly classifying positive instances and avoiding false positives and negatives. The choice of
which metric to prioritize depends on the specific requirements of your application and the
relative costs associated with different types of classification errors.
2. How do you choose the value of K in KNN?
◈ It's essential to keep in mind that the choice of K can affect both model bias and variance. Smaller
K values may result in a more complex and potentially overfit model, while larger K values may
lead to a simpler model with potentially underfitting. The optimal K value will depend on the
characteristics of your dataset and the specific problem you're trying to solve. Therefore,
exploring a range of K values and evaluating their impact on model performance is often a good
practice.
3. What are the pros and cons of using KNN for classification tasks?
◈ KNN is a versatile classification algorithm with its own set of advantages and limitations. It can
be a suitable choice for certain types of datasets and problems, especially when simplicity and
interpretability are valued. However, it may not be the best choice in cases where computational
efficiency, high-dimensional data, or optimized performance are critical considerations. The
choice of using KNN should be made based on the specific characteristics of your data and the
goals of your classification task.

Suggested Reference:
• https://www.ibm.com/topics/knn
• https://www.scaler.com/topics/machine-learning/knn-algorithm-in-machine-learning/

References used by the students:


https://scikit-learn.org/stable/index.html
Applied Machine Learning (3171617)

Rubric wise marks obtained:


Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score

Implementation Implementation is Implementation is Implementation is Implementation is


not presented. complete. It does not complete. It does not complete. It meets all
compile and run. meet all the the specifications and
specifications and does works for all test data.
not work for all test
data.

Results Results are not Partially corrected The results are correct, The results are correct.
included. results. but not in the proper Well structured,
format.

Conclusion No conclusion is In-Correct conclusion Partially correct Conclusion meets the


present. is presented. conclusion. requirements of the
experiment.

References No references are Incorrect references Related references are Related references are
included by the are included. included but are not included and well
students. well structured. structured.

Question Not able answer a Answers are partially Answers are correct. No Answers are correct.
Answers single question. correct. in-depth understating. Having in-depth
knowledge of concept.

Total

You might also like