Classification prediction | Matlab implements SO-RF snake swarm algorithm to optimize random forest multi-input classification prediction
Table of contents
List of effects
basic introduction
Matlab implements SO-RF snake swarm algorithm to optimize random forest multi-input classification prediction (complete source code and data)
Matlab snake swarm algorithm (SO) optimizes random forest (RF) classification prediction, multi-input single-output model. SO-RF classification prediction model
is a two-class and multi-class model with multiple feature inputs and single output. The comments in the program are detailed and can be used by directly replacing the data. The programming language is matlab, and the program can produce classification effect diagrams, iterative optimization diagrams, and confusion matrix diagrams.
programming
- Complete source code and data download: Matlab implements SO-RF snake swarm algorithm to optimize random forest multi-input classification prediction
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%% 清空环境变量
clc;
clear;
warning off
close all
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%% 添加路径
addpath("Toolbox\")
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%% 读取数据
res = xlsread('数据集.xlsx');
%% 性能评价
error1 = sum((T_sim1' == T_train)) / M * 100 ;
error2 = sum((T_sim2' == T_test )) / N * 100 ;
%-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%% 绘图
figure
plot(1: M, T_train, 'r-*', 1: M, T_sim1, 'b-o', 'LineWidth', 1)
legend('真实值', '预测值')
xlabel('预测样本')
ylabel('预测结果')
string = {
'训练集预测结果对比'; ['准确率=' num2str(error1) '%']};
title(string)
grid
figure
plot(1: N, T_test, 'r-*', 1: N, T_sim2, 'b-o', 'LineWidth', 1)
legend('真实值', '预测值')
xlabel('预测样本')
ylabel('预测结果')
string = {
'测试集预测结果对比'; ['准确率=' num2str(error2) '%']};
title(string)
grid
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%% 混淆矩阵
if flag_conusion == 1
figure
cm = confusionchart(T_train, T_sim1);
cm.Title = 'Confusion Matrix for Train Data';
cm.ColumnSummary = 'column-normalized';
cm.RowSummary = 'row-normalized';
figure
cm = confusionchart(T_test, T_sim2);
cm.Title = 'Confusion Matrix for Test Data';
cm.ColumnSummary = 'column-normalized';
cm.RowSummary = 'row-normalized';
end
References
[1] https://download.csdn.net/download/kjm13182345320/87899283?spm=1001.2014.3001.5503
[2] https://download.csdn.net/download/kjm13182345320/87899230?spm=1001.2014.3001.5503