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.
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]])
print " Distance from the boundary:" for i in input_datapoints: print i, '-->', classifier.decision_function(i)[0]
# Confidence measure params = {'kernel': 'rbf', 'probability': True} classifier = SVC(**params)
The probability
parameter tells the SVM that it should train to compute the probabilities as well.
classifier.fit(X_train, y_train)
print " Confidence measure:" for i in input_datapoints: print i, '-->', classifier.predict_proba(i)[0]
The predict_proba
function measures the confidence value.
utilities.plot_classifier(classifier, input_datapoints, [0]*len(input_datapoints), 'Input datapoints', 'True')
3.145.179.252