Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Machine Learning by (19k points)

I would like to get a confidence score of each of the predictions that it makes, showing on how sure the classifier is on its prediction that it is correct.

I want something like this:

How sure is the classifier on its prediction?

Class 1: 81% that this is class 1

Class 2: 10%

Class 3: 6%

Class 4: 3%

Samples of my code:

features_train, features_test, labels_train, labels_test = cross_validation.train_test_split(main, target, test_size = 0.4)

# Determine amount of time to train

t0 = time()

model = SVC()

#model = SVC(kernel='poly')

#model = GaussianNB()

model.fit(features_train, labels_train)

print 'training time: ', round(time()-t0, 3), 's'

# Determine amount of time to predict

t1 = time()

pred = model.predict(features_test)

print 'predicting time: ', round(time()-t1, 3), 's'

accuracy = accuracy_score(labels_test, pred)

print 'Confusion Matrix: '

print confusion_matrix(labels_test, pred)

# Accuracy in the 0.9333, 9.6667, 1.0 range

print accuracy

model.predict(sub_main)

# Determine amount of time to predict

t1 = time()

pred = model.predict(sub_main)

print 'predicting time: ', round(time()-t1, 3), 's'

print ''

print 'Prediction: '

print pred

I suspect that I would use the score() function, but I seem to keep implementing it correctly. I don't know if that's the right function or not, but how would one get the confidence percentage of a classifier's prediction?

1 Answer

0 votes
by (33.1k points)

It looks like you want to change the implementation of the SVC:

model = SVC(probability=True)

Simply use the predict_proba method:

class_probabilities = model.predict_proba(sub_main)

Hope this answer helps you! A better insight on this will be provided through studying the Logistic Regression and also Types Of Machine Learning

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...