www.pudn.com > Kdd-DT-NN.rar > main.m, change:2016-02-01,size:2805b


load Train.mat; 
load Test.mat; 
t=ClassificationTree.fit(DataTrain,DataTarget); 
featureName=t.PredictorNames; 
featurepredict=unique(t.CutVar'); 
indexselect=[]; 
indexNonselect=[]; 
for i=1:numel(featureName) 
    check=1; 
    for j=1:numel(featurepredict) 
        if(strcmp(featurepredict(j),featureName(i))==1) 
            indexNonselect=[indexNonselect i]; 
            check=0; 
            break; 
        end 
    end 
    if(check) 
        indexselect=[indexselect i]; 
    end 
end 
DataTrainSelect=DataTrain(:,indexselect); 
DataTrainNonSelect=DataTrain(:,indexNonselect); 
DataTestSelect=DataTest(:,indexselect); 
DataTestNonSelect=DataTest(:,indexNonselect); 
 
totalMatrix1=DataTrainSelect; 
Target1=DataTarget'; 
 
totalMatrix2=DataTestSelect; 
Target2=TestTarget'; 
 
Nclass=5; 
 
trainYG1=zeros(size(DataTrainSelect,1),Nclass); 
TestYG1=zeros(size(DataTestSelect,1),Nclass); 
for i=1:1:size(DataTrainSelect,1) 
    class=Target1(1,i); 
    trainYG1(i,class)=1; 
end 
 
for i=1:1:size(DataTestSelect,1) 
    class=Target2(1,i); 
    TestYG1(i,class)=1; 
end 
 
trainXT1=totalMatrix1'; 
trainYGT1=trainYG1'; 
 
testXT1=totalMatrix2'; 
testYGT1=TestYG1'; 
 
%% For Feature Selection 
net = newff(trainXT1,trainYGT1,20,{'tansig','tansig'},'trainlm'); 
net = init(net); 
 
%----------------------------- 
net.trainFcn = 'trainscg'; 
net.trainParam.lr = .1; 
net.trainParam.epochs = 500; 
net.trainParam.show = 10; 
net.trainParam.Performance=0.283; 
%net.trainParam.goal = 1e-3; 
net.trainParam.goal = .00100; 
net1 = train(net,trainXT1,trainYGT1); 
[testError1] = NN_evaluation(net1,testXT1,testYGT1); 
Accuracy=100-(testError1*100); 
out=sim(net1,testXT1); 
[c,cm,ind,per]=confusion(testYGT1,out); 
TP=sum(cm(:,3)); 
FP=sum(cm(:,2)); 
FN=sum(cm(:,1)); 
Precition=(TP/(TP+FP))*100; 
Recall=(TP/(TP+FN))*100; 
%% For Feature Non Selection 
 
net = newff(DataTrainNonSelect',trainYGT1,20,{'tansig','tansig'},'trainlm'); 
net = init(net); 
 
%----------------------------- 
net.trainFcn = 'trainscg'; 
net.trainParam.lr = .1; 
net.trainParam.epochs = 500; 
net.trainParam.show = 10; 
net.trainParam.Performance=0.283; 
%net.trainParam.goal = 1e-3; 
net.trainParam.goal = .00100; 
net1 = train(net,DataTrainNonSelect',trainYGT1); 
[testError1] = NN_evaluation(net1,DataTestNonSelect',testYGT1); 
AccuracyNon=100-(testError1*100); 
out=sim(net1,DataTestNonSelect'); 
[c,cm,ind,per]=confusion(testYGT1,out); 
TP=sum(cm(:,3)); 
FP=sum(cm(:,2)); 
FN=sum(cm(:,1)); 
PrecitionNon=(TP/(TP+FP))*100; 
RecallNon=(TP/(TP+FN))*100; 
 
clc; 
disp(['Accuracy Feature Selection = ' num2str(Accuracy) '  Precision = ' num2str(Precition) ' Recall =' num2str(Recall)]); 
disp(['Accuracy Non Feature Selection = ' num2str(AccuracyNon) '  Precision = ' num2str(PrecitionNon) ' Recall =' num2str(RecallNon)]);