Getting scores in Naive Bayes and Support Vector Machine

조회 수: 7 (최근 30일)
Elizabeth Vieira
Elizabeth Vieira 2016년 1월 12일
댓글: Elizabeth Vieira 2016년 1월 14일
I am using Naive Bayes and Support Vector Machine in a dataset with a binary dependent variable. I am using MatlabR2015a. I would like to get the scores when I use ScoreTransform equal to none and ScoreTransform with logit. I did some research on the subject, but I did not get results. How can I access to the scores?
Thanks in advance!
Elizabeth Vieira

채택된 답변

Brendan Hamm
Brendan Hamm 2016년 1월 12일
편집: Brendan Hamm 2016년 1월 12일
The scores are only the result from using the predict method of the aforementioned classes. They are the second output referred to as posterior.
% Load data
load fisheriris
X = meas(:,3:4);
Y = categorical(species); % 3 classes
% Remove versicolor so we have binary decision
idx = Y == 'versicolor';
X = X(~idx,:);
Y = Y(~idx,:);
Y = removecats(Y,'versicolor');
% Create a Binary Naive Bayes model w/ and w/out the score transform:
Mdl1 = fitcnb(X,Y);
Mdl2 = fitcnb(X,Y,'ScoreTransform','logit');
[grp1,score1,cost1] = predict(Mdl1,X);
[grp2,score2,cost2] = predict(Mdl2,X);
% Notice score1 has probabilities, score2 has been transformed using the logit function:
% logit(x) = 1/(1+exp(-x))
% The inverse logit is:
% ilogit(x) = -log(1/x-1);
score2Trans = -log(1./score2-1);
% Are these the same?
any(abs(score1 - score2Trans) > eps)
% voila score2Trans is within machine precision of score1.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Naive Bayes에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by