How to find out the accuracy?

First you need to import the metrics from sklearn and in metrics you need to import the accuracy_score
Then you can get the accuracy score

The accuracy_score formula is
accuracy_score=correct_predictions/No of Predictions

from sklearn.metrics import accuracy_score
accuracy_score(y_actual,y_predicted)

PS. It works great for classification techniques


Most classifiers in scikit have an inbuilt score() function, in which you can input your X_test and y_test and it will output the appropriate metric for that estimator. For classification estimators it is mostly 'mean accuracy'.

Also sklearn.metrics have many functions available which will output different metrics like accuracy, precision, recall etc.

For your specific question you need accuracy_score

from sklearn.metrics import accuracy_score
score = accuracy_score(iris.target, pr)

You have to import accuracy_score from sklearn.metrics. It should be like below,

from sklearn.metrics import accuracy_score
print accuracy_score(predictions,test set of labels)

The formula for accuracy is:

Number of points classified correctly / all the points in test set


You can use accuracy_score, find documentation here.

Implement like this -

from sklearn.metrics import accuracy_score
accuracy = accuracy_score(prediction, labels_test)

This will return a float value. The float value describes (number of points classified correctly) / (total number of points in your test set)