function [prediction, predictionError, Mdl] = generateModels(X, Y, ranked, base, fold, isDependent)
    [row, col] = size(X);
    
    prediction = repmat(Y, 1, col+1);
    predictionError = zeros(1, col+1);
    Mdl = cell(col+1,1);
    
    for i=1 : col+1
        disp(i);
        if(isDependent)
            if(i~=col+1)
                indices = ranked(1:i);
            else
                indices = [ranked(1); ranked(end)];
            end  
        else
            if(i~=col+1)
                indices = i;
            else
                indices = 1:col;
            end                      
        end
        if(strcmp(base, 'knn'))
            Mdl{i} = fitcknn(X(:,indices), Y, 'NumNeighbors', 1);
        elseif(strcmp(base, 'nb'))
            Mdl{i} = fitcnb(X(:,indices), Y, 'DistributionNames', 'normal'); % normal, mn, kernel, mvmn
        elseif(strcmp(base, 'svm'))
            t = templateSVM('Standardize', true, 'KernelFunction', 'linear'); % linear, gaussian, rbf, polynomial
            Mdl{i} = fitcecoc(X(:,indices), Y, 'Learners', t);
        elseif(strcmp(base, 'disc'))
            Mdl{i} = fitcdiscr(X(:,indices), Y, 'DiscrimType', 'linear'); % 'linear', 'pseudolinear', 'diaglinear', 'quadratic', 'diagquadratic', 'pseudoquadratic'
        elseif(strcmp(base, 'tree'))
            Mdl{i} = fitctree(X(:,indices), Y);
        elseif(strcmp(base, 'rf'))
            Mdl{i} = TreeBagger(100, X(:,indices), Y, 'OOBPrediction', 'on');
            elabel = oobPredict(Mdl{i});
            prediction(:,i) = elabel;
            predictionError(i) = 100-(sum(Y==elabel)*100/row);
            continue;
        end
        CVMdl = crossval(Mdl{i}, 'kfold', 10); %'Leaveout', 'on');
        %kloss = kfoldLoss(CVMdl);
        [elabel, ~] = kfoldPredict(CVMdl);
        prediction(:,i) = elabel;
        predictionError(i) = 100-(sum(Y==elabel)*100/row);
        %cfMat = reshape(sum(CVMdl),3,3)
        %perfcurve(Ystats,posterior(:,2,j),CVMdl.ClassNames(2));
        %kfoldfun(CVMdl,@noversicolor)
    end
end