简体   繁体   中英

MATLAB fitcsvm svm boundary equation does not separate data

I am trying to classify binary data using fitcsvm, but when I plot the boundry equation, it does not sit close to the data.

Here is the code that I used to generate the model Theme

 %creating inputs for the model
xTable = [responseData_Intensity.Intensity responseData_Intensity.ActiveForce_kg_];
y = responseData_Intensity.FeltSVM;
%-------------------------------------------------------SVM MODEL
SVMModel = fitcsvm(xTable,y);
%------------------------------------------PLOTTING THE MODEL WITH DATA
figureSVM = figure;
hold on
figTitle = strcat(participantList(participantNumber),'-',parameter,'-Maximal Margin Line');
title(figTitle);
in = responseData_Intensity.Intensity; fr = responseData_Intensity.ActiveForce_Kg_;
gscatter(in,fr,responseData_Intensity.FeltSVM,'rb');
syms x
eqn = slope*x+yIntercept == 0;
xIntercept = double(solve(eqn)); % X values where y=0
xlabel('Inensity Tested');
ylabel('Force (kg)');
plot(in(SVMModel.IsSupportVector), fr(SVMModel.IsSupportVector), 'ko', 'MarkerSize',10);
plot(in, -SVMModel.Beta(1)/SVMModel.Beta(2)*in - (SVMModel.Bias)/SVMModel.Beta(2))

legend('Not Felt','Felt','Support Vector','Classifier');

These are the values for xTable and y

xTable =
0.5000    0.5500
0.4000    0.6167
0.3000    0.4000
0.2000    0.3500
0.1000    0.6833
0.2000    0.6333
0.1000    0.4833
     0    0.6500
0.5000    0.6167
0.4000    0.5333
0.3000    0.7333
0.2000    0.7000
0.1000    0.7000
0.2000    0.6833
0.1000    0.7833
0.1000    0.6500
0.2000    0.6333
0.1000    0.8167
     0    1.1333
     0    0.8500
y =
 1
 1
 1
 1
-1
 1
-1
-1
 1
 1
 1
 1
-1
 1
 1
-1
 1
-1
 1
 1

and the resulting plot

在此处输入图像描述

which seems off because it is so far removed from the data and the support vectors. The zoomed in data is here:

在此处输入图像描述

From all the other example I've seen the line should divide the data in between the two identifiers? I may be getting some things mixed up, so any help would be very much appreciated

Figured out the answer, I needed to normalize the data, once that is done the boundary equation separatest the data nicely

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM