matlab - 10-fold cross validation for polynomial regressions -
i want utilize 10-fold cross validation method, tests polynomial form (first, second, or 3rd order) gives improve fit. want split info set 10 subsets , remove 1 subset 10 info sets. derive regression model without subset, predict output values subset using derived regression model, , computed residuals. repeat calculation routine each subset , sum squares of resulting residuals. coded next on matlab 2013b, sample info , test regression on training data. stuck on how repeat every subset , how compare polynomial form gives improve fit.
% sample info parm = [at]; n = length(parm); k = 10; % how many parts utilize allix = randperm(n); % info indices, randomly ordered numineach = ceil(n/k); % @ to the lowest degree 1 part must have many info points allix = reshape([allix nan(1,k*numineach-n)],k,numineach); p=1:k testix = allix(p,:); % indices utilize testing testix(isnan(testix)) = []; % remove nans if necessary trainix = setdiff(1:n,testix); % indices utilize training %train = parm(trainix); %gives training info %test = parm(testix); %gives testing info end % derive regression on training info sal = salinity(trainix); temp = temperature(trainix); @ = parm(trainix); xyz =[sal temp at]; % fit polynomial surface surffit = fit([xyz(:,1), xyz(:,2)],xyz(:,3), 'poly11'); % shows equation, rsquare, rmse [b,bint,r] = fit([xyz(:,1), xyz(:,2)],xyz(:,3), 'poly11');
regarding executing code every subset, can set fit within loop , store results, e.g.
% sample info parm = [at]; n = length(parm); k = 10; % how many parts utilize allix = randperm(n); % info indices, randomly ordered numineach = ceil(n/k); % @ to the lowest degree 1 part must have many info points allix = reshape([allix nan(1,k*numineach-n)],k,numineach); ball = []; bintall = []; rall = []; p=1:k testix = allix(p,:); % indices utilize testing testix(isnan(testix)) = []; % remove nans if necessary trainix = setdiff(1:n,testix); % indices utilize training %train = parm(trainix); %gives training info %test = parm(testix); %gives testing info % derive regression on training info sal = salinity(trainix); temp = temperature(trainix); @ = parm(trainix); xyz =[sal temp at]; % fit polynomial surface surffit = fit([xyz(:,1), xyz(:,2)],xyz(:,3), 'poly11'); % shows equation, rsquare, rmse [b,bint,r] = fit([xyz(:,1), xyz(:,2)],xyz(:,3), 'poly11'); ball = [ball, coeffvalues(b)]; bintall = [bintall,bint]; rall = [rall,r]; end
regarding best fit, can pick fit lowest rmse.
matlab polynomial-math cross-validation
No comments:
Post a Comment