Question
Please write in matlab! function [rmstrain rmstest] = a(filename,lowndx) % [RMSTRAIN RMSTEST]=A(LOWNDX) finds the RMS errors of 5-fold % cross-validation for the variable LOWNDX of
Please write in matlab!
function [rmstrain rmstest] = a(filename,lowndx)
% [RMSTRAIN RMSTEST]=A(LOWNDX) finds the RMS errors of 5-fold
% cross-validation for the variable LOWNDX of the data in the file
% FILENAME. The RMS errors for the training of each fold are returned
% in RMSTEST and the RMS errors for the testing of each fold are
% returned in RMSTEST.
%
% INPUTS:
% FILENAME - character string, name of file to be processed;
% assume that the first row describes the data variables
% LOWNDX - integer scalar, index into the data
% OUTPUTS:
% RMSTRAIN - 1x5 array of RMS errors for 5-fold training
% RMSTEST - 1x5 array of RMS errors for 5-fold testing
% Read the test data from a CSV file; find the size of the data
% %
% % STUDENT CODE GOES HERE: REMOVE THIS COMMENT
% % THEN READ THE FILE SPECIFIED BY THE INPUT ARGUMENT
% %
% Create Xmat and yvec from the data and the input parameter,
% accounting for no standardization of data
% %
% % STUDENT CODE GOES HERE: REMOVE THIS COMMENT
% % THEN ASSIGN THE VARIABLES FROM THE DATASET
% %
% Compute the RMS errors of 5-fold cross-validation
% %
% % STUDENT CODE GOES HERE: REMOVE THE NEXT 2 LINES AND THIS COMMENT
% % THEN PERFORM THE COMPUTATIONS
% %
rmstrain = 0.5*ones(1,5);
rmstest = 0.6*ones(1,5);
end
function [rmstrain,rmstest]=mykfold(Xmat, yvec, k_in)
% [RMSTRAIN,RMSTEST]=MYKFOLD(XMAT,yvec,K) performs a k-fold validation
% of the least-squares linear fit of yvec to XMAT. If K is omitted,
% the default is 5.
%
% INPUTS:
% XMAT - MxN data vector
% yvec - Mx1 data vector
% K - positive integer, number of folds to use
% OUTPUTS:
% RMSTRAIN - 1xK vector of RMS error of the training fits
% RMSTEST - 1xK vector of RMS error of the testing fits
% Problem size
M = size(Xmat, 1);
% Set the number of folds; must be 1 if nargin >= 3 & ~isempty(k_in) k = max(min(round(k_in), M-1), 2); else k = 5; end
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started