close all;
clear all;
clc;
dataset=xlsread('crop.xlsx','sheet1','A2:G101')
data1=dataset';
data=mapminmax(data1,0,1);
dataset=data';
num=2;
xlen=length(dataset)
cnt=25;
myrmse=zeros(4,4);
myrmse1=zeros(2,100);
for l=1:5
c=cvpartition(xlen,'holdout',0.3);
trind=training(c);
tsind=test(c);
for i=1:5
for j=1:5
for k=1:5
mdl=fitrsvm(dataset(trind,1:6),dataset(trind,7),'epsilon',2^(k-7),...
'KernelFunction','rbf', 'KernelScale',i, 'BoxConstraint',j);
res=predict(mdl,dataset(tsind,1:6));
res1=predict(mdl,dataset(trind,1:6));
temprmse=sqrt(mean((res-dataset(tsind,7)).^2));
myrmse(cnt,:)=[i j k temprmse];
myrmse1(cnt,:)=[tsind'];
cnt=cnt+1
end
end
end
end
save cropyeild myrmse1 myrmse
[a b]=min(myrmse(25:274,4));
b=b+24;
i=myrmse(b,1);
j=myrmse(b,2);
k=myrmse(b,3);
tsind=find(myrmse1(b,:));
trind=setdiff(1:xlen,tsind);
mdl=fitrsvm(dataset(trind,1:6),dataset(trind,7),'epsilon',2^(k-7),...
'KernelFunction','rbf', 'KernelScale',i, 'BoxConstraint',j);
res=predict(mdl,dataset(tsind,1:6));
res1=predict(mdl,dataset(trind,1:6));
myrmsefin= sqrt(mean((res-dataset(tsind,7)).^2));
plotregression(dataset(tsind,7),res)