How to use Kernel Ridge Regression Function in Matlab - fitrkernel
15 views (last 30 days)
Show older comments
I am trying to perform regression using kernel ridge regression in Matlab. Is there a dedicated function for Kernel Ridge Regression in Matlab?
I used the fitrkernel function, but the result is not correct. Am I doing something wrong?
Secondly, how can I specify the kernel to use.
N = 100;
data_x = linspace(0,20,N);
data_x = data_x';
data_y = sin(data_x);
[Mdl, FitInfo] = kernel_ridge_regression1(data_x, data_y);
x_test = linspace(0,15,75);
x_test = x_test';
actual_y = sin(x_test) ;
y_predict = predict(Mdl,x_test); % I used same data to test the results
figure(2)
plot(x_test,actual_y, 'o','lineWidth',2);
hold on
plot(x_test,y_predict, 'r','lineWidth',2);
legend("Original y", "Predicted y", 'interpreter','latex')
xlabel ('$x$','fontsize',18,'interpreter','latex')
ylabel('$y$','fontsize',18,'interpreter','latex')
%% FUNCTION
function [Mdl, FitInfo] = kernel_ridge_regression1(data_x_train, data_y_train)
data_x_train_b = zscore(data_x_train); % Standardize the data
[Mdl,FitInfo] = fitrkernel(data_x_train_b ,data_y_train);
end
0 Comments
Answers (1)
Anjaneyulu Bairi
on 11 Oct 2023
I Understand that you are trying to perform regression using kernel ridge regression. Try to explore the below link and download the files which has example and explanation of Kernel Ridge Regression and please note that it is a third-party support package and not provided by MathWorks.
I hope it helps to resolve your query.
0 Comments
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!