对分类数据绘图

您所在的位置:网站首页 matlab对excel数据进行分类 对分类数据绘图

对分类数据绘图

2024-05-06 05:15| 来源: 网络整理| 查看: 265

加载样本数据

加载从 100 位患者收集的样本数据。显示 patients MAT 文件中数组的数据类型和大小。

load patients whos Name Size Bytes Class Attributes Age 100x1 800 double Diastolic 100x1 800 double Gender 100x1 11412 cell Height 100x1 800 double LastName 100x1 11616 cell Location 100x1 14208 cell SelfAssessedHealthStatus 100x1 11540 cell Smoker 100x1 100 logical Systolic 100x1 800 double Weight 100x1 800 double 创建分类数组

工作区变量 Location 列出了患者就医的三个唯一医疗机构。

为了更方便地访问和比较数据,请将 Location 转换为一个 categorical 数组。

Location = categorical(Location);

汇总 categorical 数组。汇总显示每个类别在 Location 中出现的次数。

summary(Location) County General Hospital 39 St. Mary's Medical Center 24 VA Hospital 37

39 位患者在 County General Hospital 就医,24 位患者在 St. Mary's Medical Center 就医,37 位患者在 VA Hospital 就医。

工作区变量 SelfAssessedHealthStatus 包含四个唯一值 Excellent、Fair、Good 和 Poor。

将 SelfAssessedHealthStatus 转换为一个有序 categorical 数组,这样这些类别采用数学排序 Poor < Fair < Good < Excellent。

SelfAssessedHealthStatus = categorical(SelfAssessedHealthStatus,... ["Poor","Fair","Good","Excellent"],"Ordinal",true);

汇总 categorical 数组 SelfAssessedHealthStatus。

summary(SelfAssessedHealthStatus) Poor 11 Fair 15 Good 40 Excellent 34 绘制直方图

直接基于 SelfAssessedHealthStatus 创建一个直方条形图。此 categorical 数组是有序 categorical 数组。类别的顺序为 Poor < Fair < Good < Excellent,这确定了类别在图的 x 轴上的顺序。histogram 函数为四个类别中的每个类别绘制类别计数。

figure histogram(SelfAssessedHealthStatus) title("Self Assessed Health Status From 100 Patients")

仅为健康状况评估为 Fair 或 Poor 的患者绘制医院位置直方图。

figure histogram(Location(SelfAssessedHealthStatus


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3