【Matlab学习手记】ELM分类
2021-6-25 新增 github 源码和数据链接,第7个文件夹,所以,自行下载,enjoy
https://github.com/AFei19911012/MatlabSamples/tree/master/7.%20%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%E5%92%8C%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E6%A1%88%E4%BE%8B
实例:极限学习机(Extreme Learning Machine, ELM)在分类问题中的应用研究
训练集正确率Accuracy = 90.6%(453/500)
测试集正确率Accuracy = 82.6087%(57/69)
病例总数:569 良性:357 恶性:212
训练集病例总数:500 良性:316 恶性:184
测试集病例总数:69 良性:41 恶性:28
良性乳腺肿瘤确诊:37 误诊:4 确诊率p1=90.2439%
恶性乳腺肿瘤确诊:20 误诊:8 确诊率p2=71.4286%
- 代码
function Classification()
clear; clc;
% 导入数据
load data_classification.mat data
% 随机生成训练集、测试集
rng('default');
a = randperm(569);
% 训练集—500个样本
Train = data(a(1 : 500), :);
% 测试集—69个样本
Test = data(a(501 : end), :);
% 训练数据
P_train = Train(:, 3 : end)';
T_train = Train(:, 2)';
% 测试数据
P_test = Test(:, 3 : end)';
T_test = Test(:, 2)';
%% ELM
% ELM创建、训练
[IW, B, LW, TF, TYPE] = ELM_Train(P_train, T_train, 100, 'sig', 1);
% ELM仿真测试
T_sim_1 = ELM_Predict(P_train, IW, B, LW, TF, TYPE);
T_sim_2 = ELM_Predict(P_test, IW, B, LW, TF, TYPE);
%% 结果对比
% 训练集正确率
k1 = length(find(T_train == T_sim_1));
n1 = length(T_train);
Accuracy_1 = k1 / n1 * 100;
disp(['训练集正确率Accuracy = ' num2str(Accuracy_1) '%(' num2str(k1) '/' num2str(n1) ')'])
% 测试集正确率
k2 = length(find(T_test == T_sim_2));
n2 = length(T_test);
Accuracy_2 = k2 / n2 * 100;
disp(['测试集正确率Accuracy = ' num2str(Accuracy_2) '%(' num2str(k2) '/' num2str(n2) ')'])
%% 显示
count_B = length(find(T_train == 1));
count_M = length(find(T_train == 2));
total_B = length(find(data(:,2) == 1));
total_M = length(find(data(:,2) == 2));
number_B = length(find(T_test == 1));
number_M = length(find(T_test == 2));
number_B_sim = length(find(T_sim_2 == 1 & T_test == 1));
number_M_sim = length(find(T_sim_2 == 2 & T_test == 2));
disp(['病例总数:' num2str(569) ' 良性:' num2str(total_B) ' 恶性:' num2str(total_M)]);
disp(['训练集病例总数:' num2str(500) ' 良性:' num2str(count_B) ' 恶性:' num2str(count_M)]);
disp(['测试集病例总数:' num2str(69) ' 良性:' num2str(number_B) ' 恶性:' num2str(number_M)]);
disp(['良性乳腺肿瘤确诊:' num2str(number_B_sim) ' 误诊:' num2str(number_B - number_B_sim) ' 确诊率p1=' num2str(number_B_sim/number_B*100) '%']);
disp(['恶性乳腺肿瘤确诊:' num2str(number_M_sim) ' 误诊:' num2str(number_M - number_M_sim) ' 确诊率p2=' num2str(number_M_sim/number_M*100) '%']);
%% 隐含层神经元个数影响
R = zeros(10, 2);
for i = 1 : 10% ELM创建、训练[IW, B, LW, TF, TYPE] = ELM_Train(P_train, T_train, 50*i, 'sig', 1);% ELM仿真测试T_sim_1 = ELM_Predict(P_train, IW, B, LW, TF, TYPE);T_sim_2 = ELM_Predict(P_test, IW, B, LW, TF, TYPE);% 结果对比% 训练集正确率k1 = length(find(T_train == T_sim_1));n1 = length(T_train);Accuracy_1 = k1 / n1 * 100;% 测试集正确率k2 = length(find(T_test == T_sim_2));n2 = length(T_test);Accuracy_2 = k2 / n2 * 100;R(i, :) = [Accuracy_1 Accuracy_2];
end
plot(50*(1 : 10), R(:, 2), 'b:o', 'LineWidth', 2)
xlabel('隐含层神经元个数')
ylabel('测试集预测正确率(%)')
title('隐含层神经元个数对ELM性能的影响')%% 子函数
function Y = ELM_Predict(P, IW, B, LW, TF, TYPE)
%{
Input:P - Input Matrix of Training Set (R*Q)IW - Input Weight Matrix (N*R)B - Bias Matrix (N*1)LW - Layer Weight Matrix (N*S)TF - Transfer Function:'sig' for Sigmoidal function (default)'sin' for Sine function'hardlim' for Hardlim functionTYPE - Regression (0, default) or Classification (1)
Output:
Y - Simulate Output Matrix (S*Q)
%}
% Calculate the Layer Output Matrix H
Q = size(P, 2);
BiasMatrix = repmat(B, 1, Q);
tempH = IW * P + BiasMatrix;
switch TFcase 'sig'H = 1 ./ (1 + exp(-tempH));case 'sin'H = sin(tempH);case 'hardlim'H = hardlim(tempH);
end
% Calculate the Simulate Output
Y = (H' * LW)';
if TYPE == 1temp_Y = zeros(size(Y));for i = 1 : size(Y, 2)[~, index] = max(Y(:, i));temp_Y(index, i) = 1;endY = vec2ind(temp_Y);
endfunction [IW, B, LW, TF, TYPE] = ELM_Train(P, T, N, TF, TYPE)
%{
Input:P - Input Matrix of Training Set (R*Q)T - Output Matrix of Training Set (S*Q)N - Number of Hidden Neurons (default = Q)TF - Transfer Function:'sig' for Sigmoidal function (default)'sin' for Sine function'hardlim' for Hardlim functionTYPE - Regression (0, default) or Classification (1)
Output:IW - Input Weight Matrix (N*R)B - Bias Matrix (N*1)LW - Layer Weight Matrix (N*S)
%}
[R, Q] = size(P);
if TYPE == 1T = ind2vec(T);
end
% Randomly Generate the Input Weight Matrix
IW = rand(N, R) * 2 - 1;
% Randomly Generate the Bias Matrix
B = rand(N, 1);
BiasMatrix = repmat(B, 1, Q);
% Calculate the Layer Output Matrix H
tempH = IW * P + BiasMatrix;
switch TFcase 'sig'H = 1 ./ (1 + exp(-tempH));case 'sin'H = sin(tempH);case 'hardlim'H = hardlim(tempH);
end
% Calculate the Output Weight Matrix
LW = pinv(H') * T';
【Matlab学习手记】ELM分类相关推荐
- bp语音识别matlab,【Matlab学习手记】基于带动量项的BP神经网络语音识别
正确率 0.7699 1.0000 0.9275 0.9760 代码 clear; clc; % 加载四类语音信号 load data1 c1 load data2 c2 load ...
- 【Matlab学习手记】Matlab积分问题
一个程序彻底搞懂Matlab的数值积分.符号积分问题. 数值积分问题,给定被积分函数和积分上下限,使用 integral 函数得到积分值: 符号积分问题,通常结果是解析解,即需要知道被积分函数的原函数 ...
- Matlab学习手记——非线性拟合方法:压缩因子粒子群算法
目的:采用压缩因子粒子群算法实现双指数拟合. function x_opt = PSO_ExpFit2(t, Et) %{ 函数功能:压缩因子粒子群算法实现指数拟合:y = a1*exp(-x/b1) ...
- 【Matlab学习手记】标签显示在刻度之间
问题:Matlab标签和刻度线默认是对齐的,如何将标签设置到刻度线之间? 三个实例. plot类型 clear; clc; x = 0:0.1:2*pi; y = sin(x); plot(x, y) ...
- Matlab学习手记——制作GIF动图
目的:利用Matlab制作GIF动图. 结果图 测试代码 clear;clc; filename = '页岩碎屑.gif'; % 保存文件名 Iters = [1:9 10*(1:9) 100*(1: ...
- 【Matlab学习手记】sym8小波滤波
提供sym8小波,四层全局软阈值滤波源代码,采用Matlab语言编写,可移植性强. 源代码 clear;clc; load leleccum; indx = 1:3450; noisez = lele ...
- sym8 matlab,【Matlab学习手记】sym8小波滤波
提供sym8小波,四层全局软阈值滤波源代码,采用Matlab语言编写,可移植性强. 源代码 clear;clc; load leleccum; indx = 1:3450; noisez = lele ...
- 【Matlab学习手记】椭圆拟合
熟悉 Matlab 函数 nlinfit 使用. 椭圆拟合方程: 结果图: 程序: clear; clc; F = @(p, x) p(1) * x(:, 1) .^ 2 + p(2) * x(:, ...
- 【Matlab学习手记】二维码
目的:二维码的识别和生成. 代码 function varargout = QRcode(varargin) % QRCODE MATLAB code for QRcode.fig % QRCODE, ...
最新文章
- laravel php跨域请求,laravel开发中跨域的解决方案
- java异常类型和基本处理原则_Java异常控制机制和异常处理原则
- 使用sublime编译运行C程序
- vsftp的安装或升级
- VMware的“桥接”、“NAT”、“Host-only”上网方式的区别
- 自定义注解和拦截器,实现接口限流防刷
- mysql model only_full_group_by_MySql版本问题sql_mode=only_full_group_by的完美解决方案
- maven 部分命令
- css的input文本框的 propertychange、focus、blur
- PHP中功能强大却少使用的函数 -- 为你提供更多的思路
- GCC:使用图对比编码的图神经网络预训练模型 KDD2020
- openssl中算法的组织方式
- ASP.NET自定义控件示例:ASP.NET Custom control with designer integration
- Java后端实现websocket与微信小程序端连接简单例子
- mysql 统计新增用户_Mysql 查询:统计某月每日新增用户在新增当天的充值笔数、当天新增用户充值的总人数和充值总金额...
- 使用Foxmail管理hotmail邮箱时,只能接收邮件而无法发送邮件的就解决办法
- elasticsearch 分词器器读写分词
- 三星S7edge从8.0降到6.0.1,只为流畅的飞一般的感觉_我是亲民_新浪博客
- 使用分布式图计算系统实现研报关键词权重分数计算性能提升百倍以上
- Me_STM32学习笔记
热门文章
- Oracle数据库PL SQL开发、Oracle-SQL开发习题答案
- 单端反激式变换器开关稳压电源原理图 此博文包含图片	(2009-02-24 12:17:53)转载▼ 标签: 单端反激式 变换器 高频变压器 原理图 磁滞回线 磁心 杂谈	分类: technical
- 诚意干货:如何神不知鬼不觉破解你家路由器 | 硬创公开课
- 为什么对渣土车的监控和管理如此重要
- 为什么我们要使用Notes Domino?
- 抠图算法:经典的贝叶斯抠图
- java重绘jbutton_用Java着色JButton
- HTML动态爱心代码
- Js的Mixin 模式
- 看完了 vue-cli 源码,总结了这几个点