Python Learning Week 8 (Solution)

Task 1

Write a program to implement KNN classifier and classify given vector. (for k = 3)

Age Loan Class (Defaulter)
25 40000 N
35 60000 N
45 80000 N
20 20000 N
35 120000 N
52 18000 N
23 95000 Y
40 62000 Y
60 100000 Y
48 220000 Y
33 150000 Y
48 142000 ?

CODE:

139QcAJQAAAABJRU5ErkJggg== - Python Learning Week 8 (Solution)

 

QAAAABJRU5ErkJggg== - Python Learning Week 8 (Solution)

 

A+E9TTjRA7+HwAAAABJRU5ErkJggg== - Python Learning Week 8 (Solution)

wERmeYAFAN16gAAAABJRU5ErkJggg== - Python Learning Week 8 (Solution)

 

 

 

Task 2

Modify Task 1  and perform it for all odd values of k from 1 to 10.

  • Find accuracy for each value of k and display.
  • Find the best k which gives highest value of accuracy
  • Also compute confusion matrix for the best value of k.

CODE:

QoAHkCXAANNhlPDAZMBkwGTAZMBm4cxngjccAh6KioocbNDC60tJS4f882GU8MBkwGTAZMBkwGbg7GcBFUZXPA21pqMoArYxxwDhgHDAOGAeMAzXDAQMNNcNHa8U4YBwwDhgHjAMPPQcMNDz0j9gGaBwwDhgHjAPGgZrhgIGGmuGjtWIcMA4YB4wDxoGHngMGGh76R2wDNA4YB4wDxgHjQM1w4P8Dv3J2+rk2s5sAAAAASUVORK5CYII= - Python Learning Week 8 (Solution)

 

IWLkLAAAAAElFTkSuQmCC - Python Learning Week 8 (Solution)

onVphIPvS2c6FI6VdxgOTAZMBkwGTAZOBoskAOhRdys6ukvoLekCSmZmpWw1hol3GA5MBkwGTAZMBk4HiyQC7vdCpJfUX9IAExuXk5CgTMzIyxC7jgcmAyYDJgMmAyUDRZSA7O7uksIjmWyYASYly0DI3DhgHjAPGAeOAceCeOWCA5J5ZaBkYB4wDxgHjgHHAOHCvHDBAcq8ctPTGAeOAccA4YBwwDtwzBwyQ3DMLLQPjgHHAOGAcMA4YB+6VAwZI7pWDlt44YBwwDhgHjAPGgXvmwP8HnmEqMzGFPuAAAAAASUVORK5CYII= - Python Learning Week 8 (Solution)

QM8sAPjQa7UwwAAAABJRU5ErkJggg== - Python Learning Week 8 (Solution)

ERVAAAAAElFTkSuQmCC - Python Learning Week 8 (Solution)

 


What we studied in Week 8:
 In this week we study K-Nearest Neighbor Classification Model using built in function. Basically K-Nearest Neighbors is one of the most basic machine learning algorithm. This machine learning algorithm is one of the types of machine learning algorithm which is dependent on labelled input data in order to learn a function which is capable of producing an output whenever a new unlabeled data is given as input. K-NN is widely used in real life scenarios, as it is non-parametric which means that it does not make any underlying assumptions about the distributions of data and also implement this algorithm in python. This is all we have studied in this week.