How to plot my 4 classes samples to visualize each classes's representing dot?
1 次查看(过去 30 天)
显示 更早的评论
I created a features vector of more than 100 elements,then used my multiclass SVM code to classify my 106samples(91 trained,105 tested) and ended up with a classification for each of those 15 samples.Now i want to plot them in a similar way to the attached image.
%%SVM Multiclass Example
% SVM is inherently one vs one classification.
% This is an example of how to implement multiclassification using the
% one vs all approach.
TrainingSet=\[ 1 10;2 20;3 30;4 40;5 50;6 66;3 30;4.1 42;56 4;34 1\];
TestSet=\[3 34; 1 14; 2.2 25; 6.2 63\];
GroupTrain=\[1 1 2 2 2 2 3 3 4 4\];
results = multisvm(TrainingSet, GroupTrain, TestSet);
disp('multi class problem');
disp(results);
multisvm code:
numClasses=length(u);
result = zeros(length(TestSet(:,1)),1);
%build models
for k=1:numClasses
%Vectorized statement that binarizes Group
%where 1 is the current class and 0 is all other classes
G1vAll=(GroupTrain==u(k));
models(k) = svmtrain(TrainingSet,G1vAll);
end
%classify test cases
for j=1:size(TestSet,1)
for k=1:numClasses
if(svmclassify(models(k),TestSet(j,:)))
break;
end
end
result(j) = k;
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/165672/image.png)
回答(1 个)
Image Analyst
2017-6-30
If you know what class each point was assigned to, then you can use gscatter() to plot each point/spot in a different color.
1 个评论
Image Analyst
2017-6-30
It would be best to try with your data, but I don't have the multisvm function. Can you upload it along with your data. The number of points in your code doesn't match your picture.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!