Since you have used the variable name as y_pred_w_dist, make sure you change y_pred in the accuracy function to y_pred_w_dist.
In simple terms, you are still making use of the y_pred defined earlier.
Hence,as suggested, you could either rename the variable names in the accuracy method or you could overwrite the values by keeping the same variable names as shown below:
knn = KNeighborsClassifier(n_neighbors=5, weights='distance')
knn = knn.fit(X_data, y_data)
y_pred = knn.predict(X_data)
Please try this and get back for any further assistance.
Can you please look at the original code snippet, which I have posted in my question? I used the variable, which I created but not y_pred. But still I didn't get the expected answer earlier.
However, I got the answer as 1.0, once I overwritten the variables (after quitting and reloading the notebook). But, I always got the same answer in consecutive questions also. Please find the attached picture.
Could below be possibilities?
- Notebook has some issue. Even after creating new variables, the accuracy result is getting printed based on the previous calculation?
- Or the data is getting over-fit?
1.JPG 99.2 K