'How do I apply my already trained KNN classification model to new data? [closed]
I'm trying to finish a classification project, where is used KNN algorithm and worked perfectly fine. However, the issue is that I already trained the model and saved it as an RDS file. I'm wondering how would I apply the model to some new data? as for example with regression you can use the function predict() where it takes as the argument the already trained model, whereas for knn() it only takes the train dataset and test dataset, and there's no way to use an already trained knn model as an argument instead of the train dataset. Is there any function out there which would take the trained knn model as an argument to predict the classification on a new data?
Solution 1:[1]
kNN doesn't work in quite the same way as other prediction methods such as regression. Predictions are made by searching the training data for the k nearest neighbours and averaging the response variable across those k neighbours. This searching and averaging happens each time you make a prediction. As such, there is no pre-trained model - the "model" is just the pre-labelled training dataset. Predicting using kNN therefore often takes more time and memory than other prediction methods, but you can apply the training data to any new data that you want to classify in the same way as you would for the test data.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
