Matérn kernel functions for support vector regression
6 views (last 30 days)
Show older comments
Hello to all,
i have seen that for gauss process regression matern kernel functions are available. But I want to use the Martern kernel function for the support vector regression (SVR). Furthermore I want to adjust the kernel scale parameters automatically with 'OptimizeHyperparameters'.
Is there a possibility or does the martern kernel work in SVR even if it is not listed in the documentation for SVR? And is it than possible to fit the kernel scale parameter here?
0 Comments
Accepted Answer
Aditya Patil
on 21 Dec 2020
The KernelFunction argument accepts custom function. You can create a function for matern kernel, and pass it to KernelFunction argument.
However, OptimizeHyperparameters only selects one of the inbuilt Kernel functions that are provided. So it's not possible to provide a custom function to OptimizeHyperparameters.
load carsmall.mat
X = [Horsepower,Weight];
Y = MPG;
% This is how you pass custom KernelFunction
mdl = fitrsvm(X, Y, 'KernelFunction', 'myKernel');
% List out the functions you want to test
kernel = optimizableVariable('kernel', {'myKernel', 'myKernel2'}, 'Type', 'categorical');
% Define the function to optimize. Typically this will be
% the loss function on test dataset. For simplicity, I have passed the training data
fun = @(x)loss(fitrsvm(X, Y, 'KernelFunction', char(x.kernel)), X, Y);
% Run bayesian optimization
results = bayesopt(fun, [kernel]);
myKernel and myKernel2 are defined separately. You can define the required functions.
function G = myKernel(U,V)
[m, ~] = size(U);
[n, ~] = size(V);
G = ones([m,n]);
end
And,
function G = myKernel2(U,V)
[m, ~] = size(U);
[n, ~] = size(V);
G = zeros([m,n]);
end
Note that we define multiple kernel functions as kernel function itself does not take arguments except U and V.
0 Comments
More Answers (1)
See Also
Categories
Find more on Linear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!