How To Draw The ROC Curve for SVM, KNN, & Naive Bayes Classifiers?
14 ビュー (過去 30 日間)
古いコメントを表示
Hello, I'm not a professional MATLAB user, so I have some problem to find what I want. My problem is how can I draw the roc curve for SVM, KNN, & Naive Bayes Classifiers. For classification I use the "fit" to train my classifiers and "predict" to classify the test samples, and to find a roc curve I tried "plotroc" & "perfcurve", but without being able to draw curve. Can you Help me? I use MATLAB R2014a for information.
0 件のコメント
回答 (2 件)
Vladimir Calderón
2019 年 3 月 2 日
Load the sample data.
load ionosphere
X is a 351x34 real-valued matrix of predictors. Y is a character array of class labels: 'b' for bad radar returns and 'g' for good radar returns.
Reformat the response to fit a logistic regression. Use the predictor variables 3 through 34.
resp = strcmp(Y,'b'); % resp = 1, if Y = 'b', or 0 if Y = 'g'pred = X(:,3:34);
Fit a logistic regression model to estimate the posterior probabilities for an iris to be a virginica.
mdl = fitglm(pred,resp,'Distribution','binomial','Link','logit'); score_log = mdl.Fitted.Probability; % Probability estimates
Compute the standard ROC curve using the probabilities for scores.
[Xlog,Ylog,Tlog,AUClog] = perfcurve(resp,score_log,'true');
Train an SVM classifier on the same sample data. Standardize the data.
mdlSVM = fitcsvm(pred,resp,'Standardize',true);
Compute the posterior probabilities (scores).
mdlSVM = fitPosterior(mdlSVM); [~,score_svm] = resubPredict(mdlSVM);
The second column of score_svm contains the posterior probabilities of bad radar returns.
Compute the standard ROC curve using the scores from the SVM model.
[Xsvm,Ysvm,Tsvm,AUCsvm] = perfcurve(resp,score_svm(:,mdlSVM.ClassNames),'true');
Fit a naive Bayes classifier on the same sample data.
mdlNB = fitcnb(pred,resp);
Compute the posterior probabilities (scores).
[~,score_nb] = resubPredict(mdlNB);
Compute the standard ROC curve using the scores from the naive Bayes classification.
[Xnb,Ynb,Tnb,AUCnb] = perfcurve(resp,score_nb(:,mdlNB.ClassNames),'true');
Plot the ROC curves on the same graph.
plot(Xlog,Ylog) hold onplot(Xsvm,Ysvm) plot(Xnb,Ynb) legend('Logistic Regression','Support Vector Machines','Naive Bayes','Location','Best') xlabel('False positive rate'); ylabel('True positive rate'); title('ROC Curves for Logistic Regression, SVM, and Naive Bayes Classification') hold off
2 件のコメント
Tianpei Li
2019 年 6 月 28 日
mdlknn = fitcknn(X,Y,'NumNeighbors',5,'Standardize',1)
[~,score_knn] = resubPredict(mdlknn);
[Xknn,Yknn,Tknn,AUCknn] = perfcurve(Y,score_knn(:,mdlknn.ClassNames),'true');
plot(Xknn,Yknn)
SOLOMON Beyene
2019 年 11 月 8 日
I want to draw ROC curve for 6 algorithms(IBK,RF,ANN,KNN,J48,NB)
I have csv file with multclass..coulum contain features and rows contain class.
I am new user of Matlab ,can anyone help me how to load and draw in matlab
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Detection についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!