1

I have data in form of rows and columns where rows represent a record and column represents its attributes. I also have the labels (classes) for those records.

I know about decision trees concept and I would like to use matlab for classification of unseen records using decision trees.

How can this be done? I followed this link but its not giving me correct output- Decision Tree in Matlab

Essentially I want to construct a decision tree based on training data and then predict the labels of my testing data using that tree. Can someone please give me a good and working example for this ?

Community
  • 1
  • 1
Kedar Joshi
  • 1,182
  • 1
  • 20
  • 27

2 Answers2

1

I used following code to achieve it. And it is working correctly

function DecisionTreeClassifier(trainingFile, testingFile, labelsFile, outputFile)
training = csvread(trainingFile);
labels   = csvread(labelsFile);
testing  = csvread(testingFile);
tree = ClassificationTree.fit(training,labels)
prediction = predict(tree, testing)
csvwrite(outputFile, prediction)
mamdouh alramadan
  • 8,349
  • 6
  • 36
  • 53
Kedar Joshi
  • 1,182
  • 1
  • 20
  • 27
1

ClassificationTree.fit will be removed in a future release. Use fitctree instead.

Kadir GÜZEL
  • 141
  • 1
  • 1
  • 11