Extracting confidence measurements
It would be nice to know the confidence with which we classify unknown data. When a new datapoint is classified into a known category, we can train the SVM to compute the confidence level of this output as well.
How to do it…
- The full code is given in the
svm_confidence.py
file already provided to you. We will only discuss the core of the recipe here. Let's define some input data:# Measure distance from the boundary input_datapoints = np.array([[2, 1.5], [8, 9], [4.8, 5.2], [4, 4], [2.5, 7], [7.6, 2], [5.4, 5.9]])
- Let's measure the distance from the boundary:
print "\nDistance from the boundary:" for i in input_datapoints: print i, '-->', classifier.decision_function(i)[0]
- You will see the following printed on your Terminal:
- Distance from the boundary gives us some information about the datapoint, but it doesn't exactly tell us how confident the classifier is about the output tag. To do this, we need Platt scaling...