Tuesday, 16 October 2018

SVM Classification code in Matlab


 Hi All,

See a simple SVM training and testing module

// Here a student performance prediction is done

//Three inputs are marks for series1, series2 and attendance percentage

//1 indicates pass and 0 indicates fail
//Testing with [25 30 and 35

//result will be stored in classes

train1=[75 81 82 ; 30 21 40];  // Training Data

test1=[25 30 35]; // Testing Data

G=[1 0];   // Label for Training data

G=G'; // Converting to column vector

svmStruct = svmtrain(train1,G,'Kernel_Function','rbf','Method','QP');  // Create an SVM model with training data

classes = svmclassify(svmStruct,test1);  // Classification using Test data

classes  // Display output label

Decision Tree Classification in Matlab

Hi All,

Please use the code for Decision Tree Classification


---------------------------------------------------------------

train1=[30 56 1 1 1 ; 31 10 1 1 1;10 1 60 1 1;14 1 30 1 3 ; 14 1 30 1 17;6 1 25 6 1;6 1 25 17 1]; // Training Set

G=[0 1 0 0 1 0 1]; // Labels of Training data

Mdl = fitctree(train1,G); // Training Decision Tree

test1=[30 63 1 1 1]; // Testing data

hup=predict(Mdl,test1); // Testing the decision tree

--------------------------------------------------------------