Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

Test Set Method for Validation | Machine Learning | MATLAB

%Code :
x1= [1 2 3 4 5 6 7 8 9 10];%Original dataset(x coordinates)
y1= [4 2 3 1.7 1 1.2 1.5 1.9 2.3 2.7];%Original dataset(y coordinates)
x= x1([1 2 4 5 7 8 10]);%Training
y= y1([1 2 4 5 7 8 10]);%Training
x2 = x1([3 6 9]);%Test
y2 = y1([3 6 9]);%Test
plot(x,y,'b*','linewidth',3);%Plot of the training datapoints
hold on;
plot(x2,y2,'g+','linewidth',3);%Plot of the test datapoints
a=[];
for i=1:length(x)
    a=[a ; x(i) 1];
end
 c =a\y';%Linear regression coefficient calculation using training dataset
yR = c(1)*x1 + c(2); % the fitted line
plot(x1,yR,'k','linewidth',4);
legend("Training Data","Test Data","Fitted Line");
yR = c(1)*x2 + c(2); % test values
r=abs(y2-yR);%Residual


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

No comments

Popular Posts

Followers