Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show accuracy #17

Closed
ntdgo opened this issue Jul 15, 2018 · 3 comments
Closed

Show accuracy #17

ntdgo opened this issue Jul 15, 2018 · 3 comments

Comments

@ntdgo
Copy link

ntdgo commented Jul 15, 2018

Hi, I'm used KNN for my research but I don't know how to display accuracy of a result
This is my code:

# In[38]:
from sklearn import neighbors, metrics
from sklearn.neighbors import NearestNeighbors
import numpy as np
import pandas as pd
import sys
import json
import math

data    = pd.read_excel('dataset.xlsx')
data    = np.array(data.as_matrix())
# In[40]:
knn=neighbors.KNeighborsClassifier(n_neighbors=5)
# In[41]:
X = data[:,:-3]
Y = data[:,-1:]
Y = np.zeros(len(Y))
for i in range(0,len(Y)):
    if data[i,5] == 0:
        Y[i] = 0
    elif data[i,5] == 1:
        Y[i] = 1
    elif data[i,5] == 2:
        Y[i] = 2
    elif data[i,5] == 3:
        Y[i] = 3
    elif data[i,5] == 4:
        Y[i] = 4
# In[42]:
knn.fit(X, Y)
# In[49]:
result = knn.predict([[220.4, 6.39,1855]])
print(result)
# result = knn.predict(X)
# print(metrics.accuracy_score(Y[2000], result))

This is my dataset:
image
Thank you!

@abhaymise
Copy link

Can you elaborate your problem a little.
As per your code you are trying to get prediction for a sample set.
You can get proability score of the sample by calling predict_proba(X).

To get mean accuracy for a heldout data you can call score(X, y,)

@ntdgo
Copy link
Author

ntdgo commented Jul 15, 2018

image
Something wrong here, I get predict_proba from "sklearn.svm.libsvm." but it has to at least 6 arguments, could you help me!

@justmarkham
Copy link
Owner

@CrackerNo1 It seems like you could benefit from watching my video series:
https://www.youtube.com/playlist?list=PL5-da3qGB5ICeMbQuqbbCOQWcS6OYBr5A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants