Classification prediction | Matlab implements GA-RF genetic algorithm to optimize random forest multi-input classification prediction

Classification prediction | Matlab implements GA-RF genetic algorithm to optimize random forest multi-input classification prediction

Effect list

Insert image description here
Insert image description here
Insert image description here
Insert image description here

Insert image description here

basic introduction

Matlab implements GA-RF genetic algorithm to optimize random forest multi-input classification prediction (complete source code and data)
Matlab implements GA-RF genetic algorithm to optimize random forest classification prediction, multi-input single output model. GA-RF classification prediction model
is a two-classification and multi-classification 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 and confusion matrix diagrams. Optimize the depth of random forest trees.

programming

%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%%  清空环境变量
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

Guess you like

Origin blog.csdn.net/kjm13182345320/article/details/133051900