Knn implementation

sir i’m implementing knn classifier to predict fruits on feature mass,weight,height


knn function is not completed yet but its not running and showing error----->>

UFuncTypeError: ufunc ‘subtract’ did not contain a loop with signature matching types (dtype(’<U32’), dtype(’<U32’)) -> dtype(’<U32’)

so how can we remove this one ??

hey @Ashu1318,
distance is calculated between float values ( numbers ) and not string.
So , just convert that and it will work.

could u plz update it

hey @Ashu1318 ,
just change this

u=np.array(u)
v=np.array(v)

to

u=np.array(u).astype(np.float)
v=np.array(v).astype(np.float)

https://ide.codingblocks.com/s/420598 check this code its not predicting right class label ???

hey @Ashu1318 ,
do one thing upload this code on github , along with the files that you are using in this.
Create jupyter notebook , in which you can show the outputs of the code run.

here is dataset and my code plz explain how to apply knn to differentiate fruit labels

hey @Ashu1318 ,
you need to small changes in your KNN function.
just change the ending code to
new_val,counts=np.unique(new_val[:,1],return_counts=True)
idx = new_val[counts.argmax()][0]

It will work perfectly.

okay okay it working fine thankyou…

sir what is use of %matplotlib inline ??

its just a kind of substitute to calling plt.show() everytime.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.