We can use svm.SVC.score()
to evaluate the accuracy of the SVM model. I want to get the predicted class and the actual class in case of wrong predictions. How can I achieve this in scikit-learn
?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
The simplest approach is just to iterate over your predictions (and correct classifications) and do whatever you want with the output (in the following example I will just print it to stdout).
Lets assume that your data is in inputs, labels, and your trained SVM is in clf, then you can just do
It depends on what form you want the incorrect predictions to be in. For most use cases a confusion matrix should be sufficient.
A confusion matrix is a plot of the actual class vs the predicted class, such that the diagonal of the graph is all of the correct predictions, and the remaining cells are the incorrect predictions.
You can see a better example of a confusion matrix on sklearn's Confusion Matrix example.
If you just want a list of all of the misclassified values with their predicted and actual classes, you can do something like the following.
Just select all of the rows of data where the actual and predicted classes are not equal.
In this case
incorrect
would contain the following entries.You can directly make a confusion matrix using sklearn. It gives a (2*2) matrix.
Y_test: Array of your test class
Y_predicted: Array of predictions by your model
The cells of the confusion matrix will give you: True positive values, False Positive values, False Negative values and True Negative values.
Please have a look at this.