KNN is important classifier used in machine learning t for classifying the data.
- Language used: Python,
- Library used: Scikit, numpy, pandas, matplot
- Interface: Anaconda Jupyter
- Save the data file in either excel or csv format. Re-direct python directory to file location.
2. Import file and import required libraries, Identify the key features and classes in your data-set, and scatter plot to check their co-variance.
3. The output of print (df)
4. Initiate X array for the feature data-set and Y array for class data-set.
5. CASE I: In case I we shall use the entire data in data-set for training and testing again with the same data-set. Import KNN classifier and metrics. Calculate accuracy of prediction.
6.The net accuracy of training and testing on the same data.
7. CASE II: In case II we shall use the divide data-set into training and testing data-sets. Import KNN classifier,confusion matrix and metrics. Give test-size and random state as per required. Calculate accuracy of prediction.
8. Confusion matrix and net accuracy calculated where the training and testing is done on split data.
9. CASE III: In case III we shall use the cross-validation training and testing. Import KNN classifier and metrics. Give test-size and random state as per required. Apart from accuracy score, cross-validation accuracy score, precision score, recall score, F1 score is also important parameters to assess the machine learned classifier.
10. Many times it a question as to use which K value. Use the below code to figure out optimum value of k-value that gives maximum accuracy in predicting.