matlab decision tree,Decision Tree in Matlab

The documentation page of the function classregtree is self-explanatory...

Lets go over some of the most common parameters of the classification tree model: x: data matrix, rows are instances, cols are predicting attributes

y: column vector, class label for each instance

categorical: specify which attributes are discrete type (as opposed to continuous)

method: whether to produce classification or regression tree (depend on the class type)

names: gives names to the attributes

prune: enable/disable reduced-error pruning

minparent/minleaf: allows to specify min number of instances in a node if it is to be further split

nvartosample: used in random trees (consider K randomly chosen attributes at each node)

weights: specify weighted instances

cost: specify cost matrix (penalty of the various errors)

splitcriterion: criterion used to select the best attribute at each split. I'm only familiar with the Gini index which is a variation of the Information Gain criterion.

priorprob: explicitly specify prior class probabilities, instead of being calculated from the training data

A complete example to illustrate the process: %# load data load carsmall %# construct predicting attributes and target class vars = {'MPG' 'Cylinders' 'Horsepower' 'Model_Year'}; x = [MPG Cylinders Horsepower Model_Year]; %# mixed continous/discrete data y = cellstr(Origin); %# class labels %# train classification decision tree t = classregtree(x, y, 'method','classification', 'names',vars, ... 'categorical',[2 4], 'prune','off'); view(t) %# test yPredicted = eval(t, x); cm = confusionmat(y,yPredicted); %# confusion matrix N = sum(cm(:)); err = ( N-sum(diag(cm)) ) / N; %# testing error %# prune tree to avoid overfitting tt = prune(t, 'level',3); view(tt) %# predict a new unseen instance inst = [33 4 78 NaN]; prediction = eval(tt, inst) %# pred = 'Japan'

12f6bcc437161e547ddb4fea44ef8a75.png

Update:

The above classregtree class was made obsolete, and is superseded by ClassificationTree and RegressionTree classes in R2011a (see the fitctree and fitrtree functions, new in R2014a).

Here is the updated example, using the new functions/classes: t = fitctree(x, y, 'PredictorNames',vars, ... 'CategoricalPredictors',{'Cylinders', 'Model_Year'}, 'Prune','off'); view(t, 'mode','graph') y_hat = predict(t, x); cm = confusionmat(y,y_hat); tt = prune(t, 'Level',3); view(tt) predict(tt, [33 4 78 NaN])

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值