After I developed my model using KNN I get the following accuracy:
Train Accuracy :: 1
Test Accuracy :: 0.24
What is the accuracy of my model?
Data Science Stack Exchange is a question and answer site for Data science professionals, Machine Learning specialists, and those interested in learning more about the field. It only takes a minute to sign up.
Sign up to join this communityThe fact that you are getting 100% accuracy on train and 24% on test suggests that your model is extremely overfitting! This model will not perform well in the real world. You should probably try the following:
n_neighbors
you used in you KNN model is set to 1
. Use hyperparameter tuning to set this value.stratified splitting
when you split your data into train
and test
.Stratified CV
is recommended for classification.Cheers!
Hi @user150859 i try to give you a complete explain as my friend told you in previous answer so let's go:
A test accuracy of 0.24 (or 24%) indicates that your KNN model is performing poorly on the test data. There can be several reasons why this might be the case:
Overfitting: An accuracy of 1 (or 100%) on the training data suggests that your model is memorizing the training examples instead of learning the underlying patterns. This can lead to poor generalization on unseen data, resulting in low test accuracy.
Inappropriate feature selection: KNN is a distance-based algorithm, and the choice of features can greatly impact its performance. If you have selected irrelevant or noisy features, it can negatively affect the accuracy of the model.
Data imbalance: If your dataset has imbalanced classes, where some classes have significantly more samples than others, the model may struggle to accurately predict the minority classes. This can result in low overall accuracy.
Insufficient data: KNN relies on the similarity between data points to make predictions. If you have a small dataset, it might not capture the underlying patterns effectively, leading to poor performance.
Improper choice of hyperparameters: KNN has a hyperparameter k, which represents the number of nearest neighbors to consider for classification. If you have chosen an inappropriate value for k, it can affect the model's accuracy.
To improve the accuracy of your KNN model, you can consider the following steps:
It's important to experiment with different approaches and evaluate the performance of your model to iteratively improve its accuracy.
Note: As you see Overfitting is a serious problem in machine learning, our goal is to find general pattern of our data and not to be overfit on them, so be conscious about your algorithm and its regularization techniques.