Binary Classification with KNN and Logistic Regression
2 views (last 30 days)
Show older comments
To preface, I am very green with MATLAB and regression, so apologies if I am doing something wrong. I want to k-fold Cross-Validate a dataset, let's say, the classic iris dataset, using KNN (K = 5) and logistic regression exclusively (i.e. not at the same time). I wish to find the accuracy of each regression method in cross-validation, and plot each to a ROC curve. Because I want strictly binary classification of the 3 flowers from this dataset, I labeled two of the flowers as 0 and the third as 1, and appended the label to each row in the dataset's file (so now each row has a binary classification written to it). So if I load the file as, say, 'file',
X = file(:, 1:4); %%150x4 matrix of lengths and widths from the dataset
Y = file(:, 6); %%150x1 matrix of corresponding binary classifiers
I can use X and Y as axis. In respect to KNN, I think that I can fit this dataset like
Mdl = fitcknn(X,Y,'NumNeighbors',5);
and cross-validate like
CV = crossval(Mdl); %%implies 10-fold cross-validation, I think
This is as far as I have gotten after a couple days of digging for what I need, and even this may not be correct. I still want to know how I can find the accuracy of my KNN cross-validation and how I can plot it for a ROC curve. I was suggested the 'perfcurve' method, but I can't quite get it running, so to speak. I also would like some direction for doing all of this with cross-validated logistic regression as well. I know this is a lot to do, but any positive contribution helps. I will keep digging, and look forward to your responses. Thanks!
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!