close all; clear all; clc; %add dataset wholeData = csvread(''); for foldNO =1:10 A = wholeData; A(A<0)=0; Data = A(:,1:end-1); labels = A(:,end); ind = crossvalind('Kfold',labels,10); test= ind==foldNO; train = ~test; trainData = Data(train,:); trainLabels = labels(train); testData = Data(test, :); testLabels = labels(test); % class0 = []; % class1 = []; % for ii = 1:size(A, 1) % if(A(ii,(size(A, 2)))==0) % class0 = [class0; A(ii,1:(size(A, 2)-1))]; % else % class1 = [class1; A(ii,1:(size(A, 2)-1))]; % end % end class0 = []; class1 = []; for ii = 1:size(trainData, 1) if(trainLabels(ii)==0) class0 = [class0; trainData(ii,:)]; else class1 = [class1; trainData(ii,:)]; end end train_data= {class0',class1'}; train_labels=[1 2]; test_data = testData'; test_labels = testLabels' + 1; %warning off param.numHiddenLayers = 1; param.numHiddenNeurons = [3,3,10]; CC = 0; param.C = [0.01,0,100]; param.rhoValue = 0.0001; sg = 0.001; param.sigpara = [sg,sg,sg]; param.sigpara1 = [sg,sg,sg]; for m = 1:size(train_data,2) dt = normc(train_data{m}); %dt = train_data{m}; model{m} = ELM_AE(dt, param); end test_data = normc(test_data); num_test_samples = size(test_data,2); predicted_labels=[]; for jj=1:num_test_samples test_sample = test_data(:,jj); tmpErr = []; for ii =1:size(train_data,2) TY = ELM_AE_Reconstruct(test_sample, model{ii}); tmpErr(ii) = sqrt(sum((TY-test_sample).^2)); end [minVal,lb]=min(tmpErr,[],2); predicted_labels(jj) = lb(1); end acc = sum(test_labels==predicted_labels)/num_test_samples; fprintf('\naccuracy=%f\n', acc); accuracy(foldNO) = acc; end % mean(accuracy)