【问题标题】:In MATLAB how to get the result of a classification tree in a matrix?在MATLAB中如何获得矩阵中分类树的结果?
【发布时间】:2019-05-08 13:48:13
【问题描述】:

我做了一个分类树,代码:

mytree=ClassificationTree.fit(MyData,MyLables);
mytree.view('mode','graph');

我的数据有两个类,我想将预测结果作为一个矩阵来显示每个数据行属于哪个类。

data row          predicted class

1                   2
2                   1
.                   .
.                   .
.                   .

如何制作这个矩阵?

------------------已编辑----------------------

我发现使用这个函数我可以预测我的数据:

label = predict(Mdl,MyData([1:50],:));

但是这个标签属于哪些行?

【问题讨论】:

  • 预测类和MyLables不一样吗?
  • 是的,它们是一样的
  • 那么问题是什么?是生成第一列data row 的问题吗?
  • 截至编辑时,标签显然属于您输入的 1 到 50 行。

标签: matlab decision-tree


【解决方案1】:

第一列,即“数据行”,只是一个从 1 到 X 行数的向量(显然也与 Y 中的值数相同)。第二列,即“预测类”,与变量MyLables 相同。因此:

ReqResult = [(1:numel(Y)).' Y];
%Assuming Y is a column vector (order = nx1). 
%If Y is a row vector then take the transpose of Y as well.

警告:

如果您使用≥ R2014a,则应使用fitctree 而不是ClassificationTree.fit,因为正如documentation 中所述:

ClassificationTree.fit 将在未来的版本中删除。请改用fitctree

【讨论】:

    猜你喜欢
    • 2022-12-30
    • 2014-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-03
    • 1970-01-01
    • 1970-01-01
    • 2014-03-01
    相关资源
    最近更新 更多