用旧版本Matlab训练的 classregtree类的决策树model 在新版Matlab无法使用的解决方法

这篇具有很好参考价值的文章主要介绍了用旧版本Matlab训练的 classregtree类的决策树model 在新版Matlab无法使用的解决方法。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

背景

  • 想把原来r2015a版本的代码升级到r2021b,用2021b运行原来的代码时,报错
    用旧版本Matlab训练的 classregtree类的决策树model 在新版Matlab无法使用的解决方法,matlab函数,matlab,决策树
  • 搜索发现R2019a中已经去除了classregtree函数和classregtree类
    用旧版本Matlab训练的 classregtree类的决策树model 在新版Matlab无法使用的解决方法,matlab函数,matlab,决策树
    用旧版本Matlab训练的 classregtree类的决策树model 在新版Matlab无法使用的解决方法,matlab函数,matlab,决策树

解决方法

新版本的Matlab load(‘TreeModel.mat’)后,查看TreeModel的值

val = 

分类的决策树
 1  if SL<5.45 then node 2 elseif SL>=5.45 then node 3 else setosa
 2  if SW<2.8 then node 4 elseif SW>=2.8 then node 5 else setosa
 3  if SL<6.15 then node 6 elseif SL>=6.15 then node 7 else virginica
 4  class = versicolor
 5  class = setosa
 6  if SW<3.45 then node 8 elseif SW>=3.45 then node 9 else versicolor
 7  if SL<7.05 then node 10 elseif SL>=7.05 then node 11 else virginica
 8  if SL<5.75 then node 12 elseif SL>=5.75 then node 13 else versicolor
 9  class = setosa
10  if SW<2.4 then node 14 elseif SW>=2.4 then node 15 else virginica
11  class = virginica
12  class = versicolor
13  if SW<3.1 then node 16 elseif SW>=3.1 then node 17 else versicolor
14  class = versicolor
15  if SL<6.95 then node 18 elseif SL>=6.95 then node 19 else virginica
16  if SW<2.95 then node 20 elseif SW>=2.95 then node 21 else versicolor
17  class = versicolor
18  if SW<3.15 then node 22 elseif SW>=3.15 then node 23 else virginica
19  class = versicolor
20  class = versicolor
21  class = virginica
22  if SL<6.55 then node 24 elseif SL>=6.55 then node 25 else virginica
23  class = virginica
24  if SW<2.95 then node 26 elseif SW>=2.95 then node 27 else virginica
25  if SL<6.65 then node 28 elseif SL>=6.65 then node 29 else versicolor
26  if SL<6.45 then node 30 elseif SL>=6.45 then node 31 else virginica
27  class = virginica
28  class = versicolor
29  if SW<2.65 then node 32 elseif SW>=2.65 then node 33 else virginica
30  if SW<2.85 then node 34 elseif SW>=2.85 then node 35 else virginica
31  class = versicolor
32  class = virginica
33  if SW<2.9 then node 36 elseif SW>=2.9 then node 37 else versicolor
34  class = virginica
35  class = versicolor
36  class = versicolor
37  class = virginica

TreeModel共有37个nodes,
用旧版本Matlab训练的 classregtree类的决策树model 在新版Matlab无法使用的解决方法,matlab函数,matlab,决策树
决策树model就是根据特征值是否满足条件 进而判断哪一类别,因此,把model改成判断的function就可以重新调用了,每个node对应一个子function,共37个子function


function result = TreeModelFunction(Features)
% 分类的决策树
%  1  if SL<5.45 then node 2 elseif SL>=5.45 then node 3 else setosa
%  2  if SW<2.8 then node 4 elseif SW>=2.8 then node 5 else setosa
%  3  if SL<6.15 then node 6 elseif SL>=6.15 then node 7 else virginica
%  4  class = versicolor
%  5  class = setosa
%  6  if SW<3.45 then node 8 elseif SW>=3.45 then node 9 else versicolor
%  7  if SL<7.05 then node 10 elseif SL>=7.05 then node 11 else virginica
%  8  if SL<5.75 then node 12 elseif SL>=5.75 then node 13 else versicolor
%  9  class = setosa
% 10  if SW<2.4 then node 14 elseif SW>=2.4 then node 15 else virginica
% 11  class = virginica
% 12  class = versicolor
% 13  if SW<3.1 then node 16 elseif SW>=3.1 then node 17 else versicolor
% 14  class = versicolor
% 15  if SL<6.95 then node 18 elseif SL>=6.95 then node 19 else virginica
% 16  if SW<2.95 then node 20 elseif SW>=2.95 then node 21 else versicolor
% 17  class = versicolor
% 18  if SW<3.15 then node 22 elseif SW>=3.15 then node 23 else virginica
% 19  class = versicolor
% 20  class = versicolor
% 21  class = virginica
% 22  if SL<6.55 then node 24 elseif SL>=6.55 then node 25 else virginica
% 23  class = virginica
% 24  if SW<2.95 then node 26 elseif SW>=2.95 then node 27 else virginica
% 25  if SL<6.65 then node 28 elseif SL>=6.65 then node 29 else versicolor
% 26  if SL<6.45 then node 30 elseif SL>=6.45 then node 31 else virginica
% 27  class = virginica
% 28  class = versicolor
% 29  if SW<2.65 then node 32 elseif SW>=2.65 then node 33 else virginica
% 30  if SW<2.85 then node 34 elseif SW>=2.85 then node 35 else virginica
% 31  class = versicolor
% 32  class = virginica
% 33  if SW<2.9 then node 36 elseif SW>=2.9 then node 37 else versicolor
% 34  class = virginica
% 35  class = versicolor
% 36  class = versicolor
% 37  class = virginica
%
% 注意: Features 是单个样本的特征值,大小为1*2
%       这个TreeModelFunction根据特征值判断该样本属于以下三类中的哪一类:'setosa' 'virginica' 'versicolor'
%       TreeModelFunction函数只能判断单个样本的类别,如要判断多个样本的类别,请循环调用TreeModelFunction函数
% 例子:
%    >> result = TreeModelFunction([4.5 2.5])
% 
%       result =
% 
%           1×1 cell 数组
% 
%           {'versicolor'}

SL = Features(1);
SW = Features(2);

result = node01(SL,SW);

end

% --------------------------------------------------------------------------
function result = node01(SL,SW)
if SL<5.45 
    result = node02(SL,SW); 
elseif SL>=5.45 
    result = node03(SL,SW); 
else 
    result{1} = 'setosa';
end
end

function result = node02(SL,SW)
if SW<2.8  
    result = node04(SL,SW); 
elseif SW>=2.8  
    result = node05(SL,SW); 
else 
    result{1} = 'setosa';
end
end

function result = node03(SL,SW)
if SL<6.15  
    result = node06(SL,SW); 
elseif SL>=6.15  
    result = node07(SL,SW); 
else 
    result{1} = 'virginica';
end
end

function result = node04(SL,SW)
result{1} = 'versicolor';
end

function result = node05(SL,SW)
result{1} = 'setosa';
end

function result = node06(SL,SW)
if SW<3.45  
    result = node08(SL,SW); 
elseif SW>=3.45  
    result = node09(SL,SW); 
else 
    result{1} = 'versicolor';
end
end

function result = node07(SL,SW)
if SL<7.05  
    result = node10(SL,SW); 
elseif SL>=7.05  
    result = node11(SL,SW); 
else 
    result{1} = 'virginica';
end
end

function result = node08(SL,SW)
if SL<5.75  
    result = node12(SL,SW); 
elseif SL>=5.75  
    result = node13(SL,SW); 
else 
    result{1} = 'versicolor';
end
end

function result = node09(SL,SW)
result{1} = 'setosa';
end

function result = node10(SL,SW)
if SW<2.4  
    result = node14(SL,SW); 
elseif SW>=2.4  
    result = node15(SL,SW); 
else 
    result{1} = 'virginica';
end
end

function result = node11(SL,SW)
result{1} = 'virginica';
end

function result = node12(SL,SW)
result{1} = 'versicolor';
end

function result = node13(SL,SW)
if SW<3.1  
    result = node16(SL,SW); 
elseif SW>=3.1  
    result = node17(SL,SW); 
else 
    result{1} = 'versicolor';
end
end

function result = node14(SL,SW)
result{1} = 'versicolor';
end

function result = node15(SL,SW)
if SL<6.95  
    result = node18(SL,SW); 
elseif SL>=6.95  
    result = node19(SL,SW); 
else 
    result{1} = 'virginica';
end
end

function result = node16(SL,SW)
if SW<2.95  
    result = node20(SL,SW); 
elseif SW>=2.95  
    result = node21(SL,SW); 
else 
    result{1} = 'versicolor';
end
end

function result = node17(SL,SW)
result{1} = 'versicolor';
end

function result = node18(SL,SW)
if SW<3.15  
    result = node22(SL,SW); 
elseif SW>=3.15  
    result = node23(SL,SW); 
else 
    result{1} = 'virginica';
end
end

function result = node19(SL,SW)
result{1} = 'versicolor';
end

function result = node20(SL,SW)
result{1} = 'versicolor';
end

function result = node21(SL,SW)
result{1} = 'virginica';
end

function result = node22(SL,SW)
if SL<6.55  
    result = node24(SL,SW); 
elseif SL>=6.55  
    result = node25(SL,SW); 
else 
    result{1} = 'virginica';
end
end

function result = node23(SL,SW)
result{1} = 'virginica';
end

function result = node24(SL,SW)
if SW<2.95  
    result = node26(SL,SW); 
elseif SW>=2.95  
    result = node27(SL,SW); 
else 
    result{1} = 'virginica';
end
end

function result = node25(SL,SW)
if SL<6.65  
    result = node28(SL,SW); 
elseif SL>=6.65  
    result = node29(SL,SW); 
else 
    result{1} = 'versicolor';
end
end

function result = node26(SL,SW)
if SL<6.45  
    result = node30(SL,SW); 
elseif SL>=6.45  
    result = node31(SL,SW); 
else 
    result{1} = 'virginica';
end
end

function result = node27(SL,SW)
result{1} = 'virginica';
end

function result = node28(SL,SW)
result{1} = 'versicolor';
end

function result = node29(SL,SW)
if SW<2.65  
    result = node32(SL,SW); 
elseif SW>=2.65  
    result = node33(SL,SW); 
else 
    result{1} = 'virginica';
end
end

function result = node30(SL,SW)
if SW<2.85  
    result = node34(SL,SW); 
elseif SW>=2.85  
    result = node35(SL,SW); 
else 
    result{1} = 'virginica';
end
end

function result = node31(SL,SW)
result{1} = 'versicolor';
end

function result = node32(SL,SW)
result{1} = 'virginica';
end

function result = node33(SL,SW)
if SW<2.9  
    result = node36(SL,SW); 
elseif SW>=2.9  
    result = node37(SL,SW); 
else 
    result{1} = 'versicolor';
end
end

function result = node34(SL,SW)
result{1} = 'virginica';
end

function result = node35(SL,SW)
result{1} = 'versicolor';
end

function result = node36(SL,SW)
result{1} = 'versicolor';
end

function result = node37(SL,SW)
result{1} = 'virginica';
end


例子:文章来源地址https://www.toymoban.com/news/detail-832482.html

例子:
   >> result = TreeModelFunction([4.5 2.5])

      result =

          1×1 cell 数组

          {'versicolor'}

到了这里,关于用旧版本Matlab训练的 classregtree类的决策树model 在新版Matlab无法使用的解决方法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 多属性决策模型-matlab实现

    适用于评价决策问题,例如:决策目标,备选方案 影响力较强 性间独立属 容易辨别优劣 可量化 数量过多时(7)分层 表示方案对属性的偏好程 方案为行,属性为列,对每一方案每一属性取值 评价指标类型的一致化处理 一般来说,在评价指标x1,x2,…,xm(m1)中可能包括“极大

    2024年02月11日
    浏览(46)
  • Python 模型训练:逻辑回归、KNN、朴素贝叶斯、LDA、支持向量机、GBDT、决策树

    常用的分类预测模型:逻辑回归、KNN、朴素贝叶斯、LDA、SVC、GBDT、决策树 如果需要了解相关原理的话,可以另行百度,这里只讲解训练流程,废话不多说,直接开始讲解训练流程 这里用的数据就是一个普通的 DataFrame 数据,样式大概如下 第一列不需要,后面读取数据的时候

    2024年02月05日
    浏览(33)
  • 遗传算法决策变量降维的matlab实现

            遗传算法是模拟达尔文生物进化论的自然选择和遗传学机理的生物进化过程的计算模型,是一种通过模拟自然进化过程搜索最优解的方法。它最初由美国Michigan大学的J. Holland教授提出,1967年, Holland 教授的学生 Bagley在其博士论文中首次提出了“遗传算法”一词,他发展

    2024年02月11日
    浏览(30)
  • Matlab实现决策树算法(附上完整仿真源码)

    决策树是一种常见的机器学习算法,它可以用于分类和回归问题。在本文中,我们将介绍如何使用Matlab实现决策树算法。 在使用决策树算法之前,需要对数据进行预处理,包括数据清洗、缺失值处理、特征选择等。在本文中,我们使用了UCI Machine Learning Repository中的Iris数据集

    2024年02月17日
    浏览(32)
  • Matlab实现决策树算法(附上多个完整仿真源码)

    决策树是一种常见的机器学习算法,它可以用于分类和回归问题。在本文中,我们将介绍如何使用Matlab实现决策树算法。 在使用决策树算法之前,需要对数据进行预处理,包括数据清洗、缺失值处理、特征选择等。在本文中,我们使用了UCI Machine Learning Repository中的Iris数据集

    2024年02月13日
    浏览(25)
  • 决策树之ID3的matlab实现

    森林内的两条分叉路,我选择了人迹罕见的一条,从此一切变得不一样。 ------佛洛斯特Robert Frost 目录 一 .决策树介绍 1.1 相关概念 1.2 图形表示 1.3 规则表示 二.决策树的信息计算 三.ID3相关介绍 3.1 ID3算法概述 3.2 算法流程 四.matlab实现

    2024年02月11日
    浏览(44)
  • 混合整数线性规划——选址问题(决策变量0-1问题)MATLAB

    问题: 某快餐连锁经营公司有7个地点(A1,A2,…,A7)可以设立快餐 店,由于地理位置因素,设立快餐店时必须满足以下要求: A1,A2,A3三个地点最多 可选两个,A4和A5至少选取一个,A6和A7至少选取一个 。已知各个地点设立快餐店 的投入和预计收益如表所示。   已知目前

    2024年02月13日
    浏览(31)
  • 【Segment Anything Model】论文+代码实战调用SAM模型预训练权重+相关论文

    上篇文章已经全局初步介绍了SAM和其功能,本篇作为进阶使用。点击订阅专栏查看专栏列表和对应知识点,本文为seg SAM系列文章,在持续更新。

    2024年02月05日
    浏览(42)
  • stable diffusion model训练遇到的问题【No module named ‘triton‘】

    一天早晨过来,发现昨天还能跑的diffusion代码,突然出现了【No module named ‘triton’】的问题,导致本就不富裕的显存和优化速度雪上加霜,因此好好探究了解决方案。 首先是原因,由于早晨过来发现【电脑重启】导致了【训练终止】(美好的心情从看到windows更新结束),基

    2024年02月06日
    浏览(33)
  • LLM预训练大型语言模型Pre-training large language models

    在上一个视频中,您被介绍到了生成性AI项目的生命周期。 如您所见,在您开始启动您的生成性AI应用的有趣部分之前,有几个步骤需要完成。一旦您确定了您的用例范围,并确定了您需要LLM在您的应用程序中的工作方式,您的下一步就是选择一个要使用的模型。 您首先的选

    2024年02月11日
    浏览(33)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包