Thank you for the question. We will check and get back to you.
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
The one you are asking me to change is a function definition. It is not supposed to be changed if it is correct implementation.
I can call the function with the required arguments wherever it is required!
Looks like that is a correction that is to be made in the student toolkit.
Probably in the next release this problem should be resolved.
Thanks & Regards,