【问题标题】:matlab predict function error with fitrtree modelmatlab用fitrtree模型预测函数误差
【发布时间】:2017-04-01 11:34:02
【问题描述】:

我正在尝试使用 fitrtree 模型进行回归。它在没有验证的情况下工作正常,但在验证后预测函数会返回错误。

%works fine
tree = fitrtree(trainingData,target,'MinLeafSize',2, 'Leaveout','off');
y_hat = predict(tree, xNew);

%Returns error
tree = fitrtree(trainingData,target,'MinLeafSize',2, 'Leaveout','on');
y_hat = predict(tree, xNew);

错误:classreg.learning.partition.RegressionPartitionedModel 类的系统不能与“预测”一起使用 命令。首先将系统转换为已识别的模型,例如使用“idss”命令。

更新:我发现当我们使用任何类型的交叉验证时,模型位于树的 Trained 属性中,而不是树本身。这个经过训练的属性 (tree.Trained{1}) 是什么?我们从中得到什么信息?

【问题讨论】:

    标签: matlab machine-learning regression decision-tree


    【解决方案1】:

    如果您在调用fitrtree() 时选择了交叉验证方法,则函数的输出是RegressionPartitionedModel,而不是RegressionTree

    如您所说,您可以访问存储在 tree.Trained 中的 RegressionTree 类型的对象。您在此属性下找到的树的数量和含义取决于交叉验证模型。在您的情况下,使用 Leave-one-out cross-validation (LOOCV),Trained 属性包含 N RegressionTree 对象,其中 N 是训练集中数据点的数量。这些回归树中的每一个都是通过对除一个数据点之外的所有数据点进行训练而获得的。遗漏的数据点用于测试。

    例如,如果您想访问从交叉验证获得的第一棵树和最后一棵树,并将它们用于单独的预测,您可以这样做:

    %Returns RegressionPartitionedModel
    cv_trees = fitrtree(trainingData,target,'MinLeafSize',2, 'Leaveout','on');
    %This is the number of regression trees stored in cv_trees for LOOCV
    [N, ~] = size(trainingData);
    %Use one of the models from the cross-validation as a predictor
    y_hat = predict(tree.Trained{1}, xNew);
    y_hat_2 = predict(tree.Trained{N}, xNew);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      • 2019-10-05
      • 2022-01-21
      • 2017-06-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多