简体   繁体   English

如何使用决策树分类Matlab?

[英]How to use Decision Tree Classification Matlab?

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. 我了解决策树的概念,我想使用matlab使用决策树对看不见的记录进行分类。

How can this be done? 如何才能做到这一点? I followed this link but its not giving me correct output- Decision Tree in Matlab 我遵循了此链接,但没有给我正确的输出-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 ? 有人可以给我一个很好的例子吗?

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)

ClassificationTree.fit will be removed in a future release. 在将来的版本中,将会删除ClassificationTree.fit。 Use fitctree instead. 请改用fitctree。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM