SVM model always predicts same value

13 visualizzazioni (ultimi 30 giorni)
Joshua Mineroff
Joshua Mineroff il 12 Apr 2018
Risposto: Alok Nimrani il 23 Mag 2018
Hi, I am trying to use "fitrsvm" but when I use the model to predict values for a new set of data, each one gets the same result. I have no idea why this is happening and any help would be greatly appreciated. Here is the full code needed to reproduce the issue:
% Inputs
P = [2.9610 2.1504 2.4248 2.3577 2.4761 2.2290 2.2205 2.5735];
V = [229.6794 177.1193 141.9000 286.2615 239.2910 135.1531 197.6062 166.0001];
alpha = zeros(1,8);
beta = zeros(1,8);
for i = 1:8
[alpha(i),beta(i)] = Klotz(P(i),V(i));
end
X = [alpha;beta]';
% Response
SfPas = [1.0000 2.2937 2.4360 1.0005 2.2176 1.9351 2.4653 2.9268];
% Model fitting
PasMdl = fitrsvm(X,SfPas');
% Prediction
V2 = [30.32, 20.48, 24.49, 19.56]; %mL
P2 = [2.5, 2.5, 2.5, 2.5]*3; %kPa
alpha2 = zeros(1,4);
beta2 = zeros(1,4);
for i = 1:4
[alpha2(i),beta2(i)] = Klotz(P2(i),V2(i));
end
X2 = [alpha2;beta2]';
SfPas2 = predict(PasMdl,X2)'
function [alpha,beta] = Klotz(P,V)
kPa2mmHg = 7.50061561303;
P = P*kPa2mmHg; %mmHg
Pm = P; %mmHg
Vm = V; %mL
An = 27.8;
Bn = 2.76;
V0 = Vm * (0.6 - 0.006*Pm);
V30 = V0 + (Vm-V0) / ((Pm/An) ^ (1/Bn));
beta = log10(Pm/30) / log10(Vm/V30);
alpha = 30 / (V30^beta);
end

Risposte (1)

Alok Nimrani
Alok Nimrani il 23 Mag 2018
Hi Joshua,
SVMs use kernels and these kernel methods are based on distance. So, an SVM assumes that the data it works with is in a standard range, usually either 0 to 1, or -1 to 1. As a result, if the features are not scaled to comparable ranges, the features with the largest range will completely dominate in the computation of the kernel matrix. This appears to be the reason as to why you are not getting expected predicted values since the two features ‘alpha’ and ‘beta’ have different scales as can be seen in the below plot:
>> plot(X, 'LineWidth', 3)
One way to improve the results is to normalize/standardize the features in data ‘X’ prior to using this data for training an SVM model. To do so, you should use the ‘Standardize’ parameter flag with value TRUE as a Name-Value pair argument passed to the function ‘fitrsvm’ as follows:
>> PasMdl = fitrsvm(X,SfPas', 'Standardize', true);
For more information about the use of ‘Standardize’ flag, please check the following link: https://www.mathworks.com/help/stats/fitrsvm.html#busljl4-Standardize
An example where ‘Standardize’ flag is used can be checked here: https://www.mathworks.com/help/stats/fitrsvm.html#buxgtub
Alternatively, you can yourselves normalize/standardize the data as part of data pre-processing using the data normalization function ‘normalize’: https://www.mathworks.com/help/matlab/ref/normalize.html
Hope this helps.
Thanks.

Community Treasure Hunt

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

Start Hunting!

Translated by