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…

  1. 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]])
  2. 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]
  3. You will see the following printed on your ...

Get Python Machine Learning Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.