function [correlation,maxRidgeParamIndex]=ridgeCV(savePath,EEG,k,ridgeParams)
    load(savePath);
    clear classification;
    
    if strcmp(EEG,'EEG')
        trainingData=trainingDataEEG;
    elseif strcmp(EEG,'EMG')
        trainingData=trainingDataEMG;
    elseif strcmp(EEG,'LF')
        trainingData=trainingDataEEGlf;
    else
        error('only EEG,EMG and LF are valid inputs');
    end
    
    clear trainingDataEEG;
    clear trainingDataEMG;
    
    correlation=zeros(size(kinematics,2),1);
    maxRidgeParamIndex=zeros(size(kinematics,2),k);
    
    for j=1:size(kinematics,2)
        randMap=randperm(size(trainingData,1));
        kin=kinematics(:,j);
        correlations=zeros([k,1]);

        for i=1:k
            leaveData=trainingData(mod(randMap,k)==i-1,:);
            leaveKin=kin(mod(randMap,k)==i-1);
            remainingData=trainingData(mod(randMap,k)~=i-1,:);
            remainingKin=kin(mod(randMap,k)~=i-1);
            %fprintf('%s create %ith model\n',datestr(datetime('now')),i)

            [coeffs,maxRidgeParamIndex(j,i)]=kFoldRidge(remainingData,remainingKin,k,ridgeParams);

            correlations(i)=ridgeCorrelation(leaveData,leaveKin,coeffs);
        end

        correlation(j)=mean(correlations);
    end
end