0
$\begingroup$

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?

$\endgroup$

2 Answers 2

1
$\begingroup$

The 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:

  1. Increase your dataset size. Get more data and then train the model.
  2. This can also happen if the value of n_neighbors you used in you KNN model is set to 1. Use hyperparameter tuning to set this value.
  3. Use some kind of regularization to reduce the overfitting.
  4. If this is a classification problem, use stratified splitting when you split your data into train and test.
  5. Use cross validation if your dataset size is small. Stratified CV is recommended for classification.
  6. Use other models. DO not just rely on a single model. There are so many other models which work better than KNN. Try them and see which one works the best.

Cheers!

$\endgroup$
0
$\begingroup$

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:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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:

  • Perform feature selection or engineering to improve the relevance and quality of the features.
  • Address data imbalance issues using techniques such as oversampling or undersampling.
  • Gather more data if possible to provide a more comprehensive representation of the underlying patterns.
  • Tune the hyperparameters of the KNN algorithm, including the choice of k, using techniques like cross-validation.
  • Consider using other algorithms or techniques that might be better suited for your specific problem domain.

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.