Reputation: 485
I want use Support Vector Machine (SVM) for prediction. And with I have written code as follows using matlab function fitrsvm
and predict
,
tb = table(x,y)
Mdl = fitrsvm(tb,'y','KernelFunction','gaussian')
YFit = predict(Mdl,tb);
scatter(x,y);
hold on
plot(x,YFit,'r.')
The output I am getting .
Here blude is testing values (tb
) and red is prediction using SVM. As you can clearly see this prediction is wrong. Could anyone tell me any way to improve the prediction close to the measured values ?
Upvotes: 4
Views: 4065
Reputation: 447
you should use Kernel Function like RBF or gaussian and so on.
the default Kernel of the SVM is K(xi, xj) = xi*xj
and it is a linear kernel.Of course you can only get a linear regression result.
Code like
x = 0:0.01:5 ;
y = sin(x)+rand(1, length(x)) ;
x = x' ;
y = y' ;
tb = table(x,y) ;
Mdl = fitrsvm(tb,'y','KernelFunction','gaussian');
YFit = predict(Mdl,tb);
scatter(x,y);
hold on
plot(x,YFit,'r.')
=======================================================================
As for the accuracy of the result, it dependst on many factors like the type of Kernel, the punish coefficient adjustment or something else, it usually needs for times to adjust the parameters. cross-validation could help you to find a good set of parameters
Upvotes: 3