Validation by leave-one-out (LOOCV) | MATLAB

Core Idea:

As the name suggests, the validation is performed by leaving only one sample out of the training set: all the samples except the one left out are used as a training set, and the classification method is validated on the sample left out. If this procedure is performed only once, then the
result would be statistically irrelevant as well. The procedure is indeed performed as many times as the number of samples in the training set, that one by one are taken out of the training set. The overall accuracy of the classifications of the samples left out gives an evaluation of the classification method.
Short form:LOOCV(Leave one out cross validation)

%Code: 
clc
clear all
close all
x1= [1 2 3 4 5 6 7 8 9 10];
y1= [4 2 3 1.7 1 1.2 1.5 1.9 2.3 2.7];
error=[];
error2=[];
for i=1:length(x1)
a=2;
x=[];
y=[];
for ij=1:length(x1)
    if(ij~=i)
        x=[x x1(ij)];
        y=[y y1(ij)];
    end
end
coeff=polyfit(x,y,a);
temp=a;
c=0;
t1=x1(i);
for j=1:length(coeff)
c=c+coeff(j)*(t1^temp);
temp=temp-1;
end
temp=a;
exa=polyval(c,t1);
error=[error abs(y1(i)-c)];
error2=[error2 abs(y1(i)-exa)];
c=0;
end

Join us on Telegram: https://t.me/matlabirawen
Join us on Facebook Group: https://www.facebook.com/groups/matlabcodes


No comments

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();