How to show hyperplane in SVM for multiclass classification(fitcecoc)

1 view (last 30 days)
a=[1 24.2900000000000 179.330000000000
1 6.14000000000000 88.8400000000000
1 5.59000000000000 174.300000000000
1 6.42000000000000 110.120000000000
1 24.2900000000000 174.300000000000
1 6.14000000000000 89.6800000000000
1 5.59000000000000 173.050000000000
1 6.42000000000000 109.190000000000
1 24.7500000000000 187.070000000000
1 6.14000000000000 88.8400000000000
1 5.32000000000000 173.050000000000
1 6.42000000000000 109.190000000000
1 26.1500000000000 179.330000000000
1 6.14000000000000 88.8400000000000
1 5.32000000000000 173.050000000000
1 6.42000000000000 109.190000000000
1 24.2900000000000 181.890000000000
1 6.14000000000000 88.8400000000000
1 5.59000000000000 173.050000000000
1 6.42000000000000 109.190000000000
1 24.2900000000000 179.330000000000
1 6.14000000000000 88.8400000000000
1 5.59000000000000 173.050000000000
1 6.42000000000000 109.190000000000
1 24.2900000000000 178.070000000000
1 6.14000000000000 88.8400000000000
1 5.59000000000000 173.050000000000
1 6.42000000000000 109.190000000000
1 24.2900000000000 176.800000000000
1 6.14000000000000 88.8400000000000
1 5.59000000000000 173.050000000000
1 6.42000000000000 109.190000000000
1 24.2900000000000 174.300000000000
1 6.14000000000000 88.8400000000000
1 5.59000000000000 173.050000000000
1 6.42000000000000 109.190000000000
1 24.2900000000000 183.170000000000
1 6.14000000000000 88.8400000000000
1 5.59000000000000 171.820000000000
1 6.42000000000000 109.190000000000
1 24.2900000000000 184.470000000000
1 6.14000000000000 88.8400000000000
1 5.59000000000000 171.820000000000
1 6.42000000000000 109.190000000000
1 24.7500000000000 169.360000000000
1 6.14000000000000 88.8400000000000
1 5.59000000000000 171.820000000000
1 6.42000000000000 109.190000000000
1 24.2900000000000 176.800000000000
1 6.14000000000000 88.8400000000000
1 5.59000000000000 171.820000000000
1 6.42000000000000 108.250000000000
1 24.7500000000000 175.550000000000
1 6.14000000000000 88.8400000000000
1 5.32000000000000 171.820000000000
1 6.42000000000000 108.250000000000
1 24.7500000000000 178.070000000000
1 6.14000000000000 88.0100000000000
1 5.32000000000000 171.820000000000
1 6.42000000000000 108.250000000000
1 24.7500000000000 178.070000000000
1 6.14000000000000 88.0100000000000
1 5.32000000000000 171.820000000000
1 6.42000000000000 108.250000000000
1 24.7500000000000 180.610000000000
1 6.14000000000000 88.0100000000000
1 5.32000000000000 171.820000000000
1 6.42000000000000 108.250000000000
1 24.2900000000000 187.070000000000
1 6.14000000000000 88.0100000000000
1 5.32000000000000 171.820000000000
1 6.42000000000000 108.250000000000
1 24.7500000000000 176.800000000000
1 6.14000000000000 88.0100000000000
1 5.32000000000000 171.820000000000
1 6.42000000000000 108.250000000000
1 24.2900000000000 189.690000000000
1 6.14000000000000 88.0100000000000
1 5.32000000000000 171.820000000000
1 6.42000000000000 108.250000000000
1 24.7500000000000 179.330000000000
1 6.70000000000000 88.0100000000000
1 5.32000000000000 171.820000000000
1 6.42000000000000 108.250000000000
2 35.2000000000000 179.330000000000
2 9.12000000000000 88.8400000000000
2 10.4200000000000 174.300000000000
2 10.7600000000000 110.120000000000
2 34.6600000000000 174.300000000000
2 8.80000000000000 89.6800000000000
2 10.4200000000000 173.050000000000
2 10.7600000000000 109.190000000000
2 34.6600000000000 187.070000000000
2 9.12000000000000 88.8400000000000
2 10.4200000000000 173.050000000000
2 10.7600000000000 109.190000000000
2 35.2000000000000 179.330000000000
2 9.12000000000000 88.8400000000000
2 10.4200000000000 173.050000000000
2 10.7600000000000 109.190000000000
2 34.6600000000000 181.890000000000
2 9.12000000000000 88.8400000000000
2 10.4200000000000 173.050000000000
2 10.7600000000000 109.190000000000
2 35.2000000000000 179.330000000000
2 8.80000000000000 88.8400000000000
2 10.4200000000000 173.050000000000
2 10.7600000000000 109.190000000000
2 34.6600000000000 178.070000000000
2 9.12000000000000 88.8400000000000
2 10.4200000000000 173.050000000000
2 10.7600000000000 109.190000000000
2 35.2000000000000 176.800000000000
2 9.12000000000000 88.8400000000000
2 10.4200000000000 173.050000000000
2 10.7600000000000 109.190000000000
2 35.2000000000000 174.300000000000
2 8.80000000000000 88.8400000000000
2 10.4200000000000 173.050000000000
2 10.7600000000000 109.190000000000
2 35.2000000000000 183.170000000000
2 9.12000000000000 88.8400000000000
2 10.4200000000000 171.820000000000
2 10.7600000000000 109.190000000000
2 34.6600000000000 184.470000000000
2 8.80000000000000 88.8400000000000
2 10.4200000000000 171.820000000000
2 10.7600000000000 109.190000000000
2 34.6600000000000 169.360000000000
2 8.80000000000000 88.8400000000000
2 10.4200000000000 171.820000000000
2 10.7600000000000 109.190000000000
2 34.6600000000000 176.800000000000
2 8.80000000000000 88.8400000000000
2 10.4200000000000 171.820000000000
2 10.7600000000000 108.250000000000
2 35.2000000000000 175.550000000000
2 9.12000000000000 88.8400000000000
2 10.4200000000000 171.820000000000
2 10.7600000000000 108.250000000000
2 34.6600000000000 178.070000000000
2 9.12000000000000 88.0100000000000
2 10.4200000000000 171.820000000000
2 10.7600000000000 108.250000000000
2 35.2000000000000 178.070000000000
2 9.12000000000000 88.0100000000000
2 10.4200000000000 171.820000000000
2 10.7600000000000 108.250000000000
2 34.6600000000000 180.610000000000
2 9.12000000000000 88.0100000000000
2 10.4200000000000 171.820000000000
2 10.7600000000000 108.250000000000
2 35.2000000000000 187.070000000000
2 8.80000000000000 88.0100000000000
2 10.4200000000000 171.820000000000
2 10.7600000000000 108.250000000000
2 34.6600000000000 176.800000000000
2 9.12000000000000 88.0100000000000
2 10.4200000000000 171.820000000000
2 10.7600000000000 108.250000000000
2 35.2000000000000 189.690000000000
2 8.80000000000000 88.0100000000000
2 10.4200000000000 171.820000000000
2 10.7600000000000 108.250000000000
2 34.6600000000000 179.330000000000
2 9.12000000000000 88.0100000000000
2 10.4200000000000 171.820000000000
2 10.7600000000000 108.250000000000
3 41.2800000000000 179.330000000000
3 12.4900000000000 88.8400000000000
3 17.8200000000000 174.300000000000
3 17.4100000000000 110.120000000000
3 41.8500000000000 174.300000000000
3 12.4900000000000 89.6800000000000
3 17.8200000000000 173.050000000000
3 17.4100000000000 109.190000000000
3 41.2800000000000 187.070000000000
3 12.8500000000000 88.8400000000000
3 17.8200000000000 173.050000000000
3 17.4100000000000 109.190000000000
3 41.8500000000000 179.330000000000
3 12.8500000000000 88.8400000000000
3 17.8200000000000 173.050000000000
3 17.4100000000000 109.190000000000
3 41.2800000000000 181.890000000000
3 12.4900000000000 88.8400000000000
3 17.8200000000000 173.050000000000
3 17.4100000000000 109.190000000000
3 41.8500000000000 179.330000000000
3 12.8500000000000 88.8400000000000
3 18.2200000000000 173.050000000000
3 17.4100000000000 109.190000000000
3 41.2800000000000 178.070000000000
3 12.8500000000000 88.8400000000000
3 17.8200000000000 173.050000000000
3 17.4100000000000 109.190000000000
3 41.2800000000000 176.800000000000
3 12.8500000000000 88.8400000000000
3 17.8200000000000 173.050000000000
3 17.4100000000000 109.190000000000
3 41.2800000000000 174.300000000000
3 12.8500000000000 88.8400000000000
3 17.8200000000000 173.050000000000
3 17.4100000000000 109.190000000000
3 41.2800000000000 183.170000000000
3 12.4900000000000 88.8400000000000
3 18.2200000000000 171.820000000000
3 17.4100000000000 109.190000000000
3 41.2800000000000 184.470000000000
3 12.4900000000000 88.8400000000000
3 18.2200000000000 171.820000000000
3 17.4100000000000 109.190000000000
3 41.2800000000000 169.360000000000
3 12.8500000000000 88.8400000000000
3 17.8200000000000 171.820000000000
3 17.4100000000000 109.190000000000
3 41.2800000000000 176.800000000000
3 12.8500000000000 88.8400000000000
3 17.8200000000000 171.820000000000
3 17.4100000000000 108.250000000000
3 41.8500000000000 175.550000000000
3 12.4900000000000 88.8400000000000
3 17.8200000000000 171.820000000000
3 17.4100000000000 108.250000000000
3 41.2800000000000 178.070000000000
3 12.8500000000000 88.0100000000000
3 18.2200000000000 171.820000000000
3 17.4100000000000 108.250000000000
3 41.8500000000000 178.070000000000
3 12.8500000000000 88.0100000000000
3 18.2200000000000 171.820000000000
3 17.4100000000000 108.250000000000
3 41.8500000000000 180.610000000000
3 12.4900000000000 88.0100000000000
3 17.8200000000000 171.820000000000
3 17.8200000000000 108.250000000000
3 41.8500000000000 187.070000000000
3 12.8500000000000 88.0100000000000
3 18.2200000000000 171.820000000000
3 17.4100000000000 108.250000000000
3 41.8500000000000 176.800000000000
3 12.4900000000000 88.0100000000000
3 17.0100000000000 171.820000000000
3 17.4100000000000 108.250000000000
3 41.8500000000000 189.690000000000
3 12.4900000000000 88.0100000000000
3 18.2200000000000 171.820000000000
3 17.4100000000000 108.250000000000
3 41.2800000000000 179.330000000000
3 12.8500000000000 88.0100000000000
3 18.2200000000000 171.820000000000
3 17.4100000000000 108.250000000000
4 56.7200000000000 179.330000000000
4 27.1000000000000 88.8400000000000
4 22.4900000000000 174.300000000000
4 22.4900000000000 110.120000000000
4 56.0600000000000 174.300000000000
4 27.1000000000000 89.6800000000000
4 22.4900000000000 173.050000000000
4 22.4900000000000 109.190000000000
4 56.0600000000000 187.070000000000
4 27.1000000000000 88.8400000000000
4 22.4900000000000 173.050000000000
4 22.4900000000000 109.190000000000
4 56.0600000000000 179.330000000000
4 27.1000000000000 88.8400000000000
4 22.4900000000000 173.050000000000
4 22.4900000000000 109.190000000000
4 56.0600000000000 181.890000000000
4 26.6200000000000 88.8400000000000
4 22.4900000000000 173.050000000000
4 22.4900000000000 109.190000000000
4 56.0600000000000 179.330000000000
4 26.6200000000000 88.8400000000000
4 22.4900000000000 173.050000000000
4 22.4900000000000 109.190000000000
4 56.0600000000000 178.070000000000
4 27.1000000000000 88.8400000000000
4 22.4900000000000 173.050000000000
4 22.4900000000000 109.190000000000
4 56.0600000000000 176.800000000000
4 26.6200000000000 88.8400000000000
4 22.4900000000000 173.050000000000
4 22.4900000000000 109.190000000000
4 56.0600000000000 174.300000000000
4 26.6200000000000 88.8400000000000
4 22.4900000000000 173.050000000000
4 22.4900000000000 109.190000000000
4 56.0600000000000 183.170000000000
4 26.6200000000000 88.8400000000000
4 22.4900000000000 171.820000000000
4 22.4900000000000 109.190000000000
4 56.0600000000000 184.470000000000
4 26.6200000000000 88.8400000000000
4 22.4900000000000 171.820000000000
4 22.4900000000000 109.190000000000
4 56.0600000000000 169.360000000000
4 26.6200000000000 88.8400000000000
4 22.4900000000000 171.820000000000
4 22.4900000000000 109.190000000000
4 56.0600000000000 176.800000000000
4 26.6200000000000 88.8400000000000
4 22.4900000000000 171.820000000000
4 22.4900000000000 108.250000000000
4 56.0600000000000 175.550000000000
4 26.6200000000000 88.8400000000000
4 22.4900000000000 171.820000000000
4 22.4900000000000 108.250000000000
4 56.0600000000000 178.070000000000
4 26.6200000000000 88.0100000000000
4 22.9300000000000 171.820000000000
4 22.4900000000000 108.250000000000
4 56.0600000000000 178.070000000000
4 26.6200000000000 88.0100000000000
4 22.4900000000000 171.820000000000
4 22.4900000000000 108.250000000000
4 56.0600000000000 180.610000000000
4 26.6200000000000 88.0100000000000
4 22.4900000000000 171.820000000000
4 22.4900000000000 108.250000000000
4 56.0600000000000 187.070000000000
4 26.6200000000000 88.0100000000000
4 22.4900000000000 171.820000000000
4 22.4900000000000 108.250000000000
4 56.0600000000000 176.800000000000
4 26.6200000000000 88.0100000000000
4 22.4900000000000 171.820000000000
4 22.4900000000000 108.250000000000
4 56.0600000000000 189.690000000000
4 26.6200000000000 88.0100000000000
4 22.4900000000000 171.820000000000
4 22.4900000000000 108.250000000000
4 56.0600000000000 179.330000000000
4 26.6200000000000 88.0100000000000
4 22.4900000000000 171.820000000000
4 22.4900000000000 108.250000000000]
X=a(:,2:3);
Y=a(:,1);%classes
figure
gscatter(X(:,1),X(:,2),Y);
xlabel('Petal Length (cm)');
ylabel('Petal Width (cm)');
t = templateSVM( 'KernelFunction', 'linear', 'Standardize', true);
Mdl = fitcecoc( X,Y,'Learners', t);
%% Now I need the hyperplanes for the above multiclass classification
%
Now I need the hyperplanes for the above multiclass classification showing data saperation,

Answers (1)

Abhaya
Abhaya on 3 Dec 2024
Hi Sanjib,
I understand you want to create a visualization of the hyperplanes for the multiclass classification to illustrate the separation of the data.
To achieve this, you can follow the steps given below.
  • Create a grid of points for plotting the decision boundary
[x1Grid, x2Grid] = meshgrid(linspace(min(X(:, 1)), max(X(:, 1)), 500), linspace(min(X(:, 2)), max(X(:, 2)), 500));
XGrid = [x1Grid(:), x2Grid(:)];
  • Predict the class for each point in the grid
predictedLabels = predict(SVMModel, XGrid);
  • Reshape the predictions to match the grid size
predictedLabels = reshape(predictedLabels, size(x1Grid));
  • Plot the decision boundaries
hold on;
contour(x1Grid, x2Grid, predictedLabels, 'LineWidth', 1, 'LineColor', 'k');
hold off;
For more information, please refer to following MATLAB documentations on ‘meshgrid’ function and ‘contour’ function.
Additionally, you may refer to the following MATLAB community discussion for additional techniques on visualizing multiclass SVM decision boundaries.
Hope this solves your query.

Community Treasure Hunt

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

Start Hunting!