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

背景

  • 想把原来r2015a版本的代码升级到r2021b,用2021b运行原来的代码时,报错
    在这里插入图片描述
  • 搜索发现R2019a中已经去除了classregtree函数和classregtree类
    在这里插入图片描述
    在这里插入图片描述

解决方法

新版本的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,
在这里插入图片描述
决策树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


例子:

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

      result =

          1×1 cell 数组

          {'versicolor'}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/407347.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Ubuntu安装中文拼音输入法

目录 1.添加中文语言支持2.安装fcitx输入法框架3.设置fcitx为系统输入法4.安装搜狗输入法5.安装一些搜狗输入法的依赖6.设置输入法7.测试搜狗中文输入法8.测试版本参考资料 1.添加中文语言支持 settings -> region & language -> Manage Installed Languages -> …

【海思新品型号总结】

海思新品如下型号&#xff1a; 1、 Hi3559AV100 pin to pin 老版本&#xff1b; 2、Hi3403V100 4K/60 丝印1&#xff1a;108DC2910 开发包型号SS928V100 不可溯源&#xff1b; 丝印2&#xff1a;GK7608V100 开发包型号SS928V100 可国产化证明 3、Hi3519AV200 芯片丝印&#x…

Maven - 代码混淆proguard-maven-plugin vs 代码加密classfinal

文章目录 proguard-maven-plugin 代码混淆官网地址入门小结 ClassFinal 代码加密介绍Gitee项目模块说明功能特性环境依赖使用说明下载加密maven插件方式无密码模式机器绑定启动加密后的jartomcat下运行加密后的war 版本说明协议声明 classfinal实战工程pom编译打包配置文件运行…

MySQL知识点总结(五)——锁

MySQL知识点总结&#xff08;五&#xff09;——锁 锁分类表锁 & 行锁如何添加表锁&#xff1f;如何添加行锁&#xff1f; 读锁 & 写锁行锁 & 间隙锁&#xff08;gap lock&#xff09;& 临键锁&#xff08;next-key lock&#xff09; 加锁机制分析可重复读隔离…

【雷达指标】MTI/MTD性能

目录 一、MTI/MTD性能的指标描述1.1 杂波衰减和对消比1.2 改善因子1.3 杂波中的可见度 二、MATLAB仿真参考文献 雷达通常使用MTI/MTD来进行杂波抑制&#xff0c;采用杂波衰减、对消比、改善因子、杂波中的可见度来描述其性能。 一、MTI/MTD性能的指标描述 1.1 杂波衰减和对消比…

在 where子句中使用子查询(一)

目录 子查询返回单行单列 查询公司工资最低的员工信息 查找公司雇佣最早的员工信息 子查询返回单行多列 查询与 ALLEN 工资相同&#xff0c;职位相同的所有员工信息 子查询返回多行单列 IN 操作 查询职位是“MANAGER”的所有员工的薪水 Oracle从入门到总裁:https://bl…

医院信息系统(HIS):一文扫盲,算是所有信息系统里面复杂的

大家好&#xff0c;我是贝格前端工场&#xff0c;本期继续分享常见的B端管理系统&#xff0c;欢迎大家关注&#xff0c;如有B端写系统界面的设计和前端需求&#xff0c;可以联络我们。 一、什么是HIS系统 HIS系统&#xff08;Hospital Information System&#xff09;是医院信…

【更换yarn的位置】解决yarn和nodejs不在同一盘下产生的某些命令应用失败问题

具体问题我记得是command fail什么error&#xff0c;记不太清楚了&#xff0c;文章主要写了如何替换yarn路径&#xff0c;希望可以帮助到大家。

Pycharm服务器配置与内网穿透工具结合实现远程开发的解决方法

文章目录 一、前期准备1. 检查IDE版本是否支持2. 服务器需要开通SSH服务 二、Pycharm本地链接服务器测试1. 配置服务器python解释器 三、使用内网穿透实现异地链接服务器开发1. 服务器安装Cpolar2. 创建远程连接公网地址 四、使用固定TCP地址远程开发 本文主要介绍如何使用Pych…

【Linux】docker构建环境编译运行linux内核

文章目录 1. 使用docker构建linux内核编译运行环境1.1. 为普通用户安装docker并验证是否安装成功1.1.1. 安装docker稳定版1.1.2. 启动docker1.1.3. 将当前用户加入docker用户组1.1.4. 验证docker是否安装成功 1.2. docker基本使用1.2.1. 列出所有镜像1.2.2. 查看当前所有容器的…

liunx gcc编译器 以及编译过程

liunx编译器gcc 编译过程 编译过程gccgcc的条件编译gcc 编译指令动态库和静态库 编译过程 预处理 &#xff08;1&#xff09;将所有的#define删除&#xff0c;并且展开所有的宏定义。说白了就是字符替换 &#xff08;2&#xff09;处理所有的条件编译指令&#xff0c;#ifdef …

渗透工具——kali中wpscan简介

一、什么是wpscan 1、常用于做用户名枚举爆破 2、WPScan是一个扫描 WordPress 漏洞的黑盒子扫描器&#xff0c;它可以为所有 Web 开发人员扫描 WordPress 漏洞并在他们开发前找到并解决问题。我们还使用了 Nikto &#xff0c;它是一款非常棒的Web 服务器评估工具&#xff0c;…

1.系统调用接口

1. 系统调用接口 1.1 Linux系统调用概念 系统调用&#xff08;systemcall&#xff09;&#xff1a; 所有的操作系统在内核里都有一些内建的函数&#xff0c;这些函数完成对硬件的访问和对文件的打开、读、写、关闭等操作。 Linux 系统中称这些函数为系统调用。这些函数实现了…

TypeScript基础知识点

TypeScript 简介和发展 TypeScript 是一种由微软开发的开源编程语言&#xff0c;其设计目标是为了解决 JavaScript 在大规模应用开发时所面临的类型安全和可维护性问题。TypeScript 的诞生背景可以追溯到2012年&#xff0c;当时随着Web应用程序复杂度的日益增长&#xff0c;J…

五、使用脚手架

五、使用脚手架 5.1 简单的实现 创建一个 School 组件 <template> <div><h2>学校名称&#xff1a;{{name}}</h2><h2>学校地址&#xff1a;{{address}}</h2> </div> </template><script> export default {name: "S…

python[5]

数据容器的通用操作 通用 for 循环 便历容器&#xff08;字典是遍历Key&#xff09; max 容器内最大元素 min( ) 容器内最小元素 len( ) 容器元素个数 list( ) 转换为列表 tuple( ) 转换为元组 str( ) 转换为字符串 set( ) 转换为集合 sorted(序列, reverse True) 排序&#…

【JavaEE Spring 项目】在线 OJ 系统

在线OJ系统 1. 需求2. 最终页面展示3. 需求分析4. 创建 Spring 项目5. 前后端交互接口约定6. 后端功能实现6.1 编译运行模块6.1.1 进程和线程的相关知识6.1.2 Java 中的多进程编程6.1.3 进程间通信 -- 文件6.1.4 Java中的 IO 知识6.1.5 封装创建进程执行命令工具类6.1.6 实现编…

遍历的三种算法——递归、非递归、层次

一、递归遍历方法&#xff1a; 先序遍历&#xff1a; Status PreOrderTraverse(Tree *t) {if (t NULL) return OK;//合法性检查else {visit(t->data);//访问根节点PreOrderTraverse(t->lchild);//递归遍历左子树PreOrderTraverse(t->rchild);//递归遍历右子树} } …

群晖NAS DSM7.2.1安装宝塔之后无法登陆账号密码问题解决

宝塔的安装就不在这赘述了&#xff0c;只说下&#xff0c;启动之后默认账号密码无法登陆的问题。 按照上面给出的账号密码&#xff0c;无法登陆 然后点忘记密码&#xff0c;由于是docker安装的&#xff0c;根目录下没有/www/server/panel 。 也没有bt命令 要怎么修改呢。 既然…

深入探索pdfplumber:从PDF中提取信息到实际项目应用【第94篇—pdfplumbe】

深入探索pdfplumber&#xff1a;从PDF中提取信息到实际项目应用 在数据处理和信息提取的过程中&#xff0c;PDF文档是一种常见的格式。然而&#xff0c;要从PDF中提取信息并进行进一步的分析&#xff0c;我们需要使用适当的工具。本文将介绍如何使用Python库中的pdfplumber库来…