random forest block in simulink

조회 수: 10 (최근 30일)
insherah
insherah 2025년 3월 4일
댓글: insherah 2025년 3월 6일

I need guidance how to create random forest block in simulink My coding use tree bagger for classification

채택된 답변

aditi bagora
aditi bagora 2025년 3월 6일
I understand that you want to use a trained Random Forest model for prediction in Simulink, utilize the ClassificationEnsemble Predict block.
  1. If you already have a trained model in your workspace, simply load it via the 'Select trained machine learning model' option in the block parameters.
  2. If you don't have a trained model yet, you can refer to the follwowing example: https://www.mathworks.com/help/stats/predict-class-labels-using-classification-ensemble-predict-block.html
For further details, explore these MathWorks documentation links on the ClassificationEnsemble Predict block and ClassificationBaggedEnsemble:
  댓글 수: 1
insherah
insherah 2025년 3월 6일

% %Random Forest % Load feature and target tables Input = xlsread('Feature Table (LL_LLG_LG_LLL) x2.xlsx'); Target = xlsread('Target Table (LL_LLG_LG_LLL) x2.xlsx');

% Split ratio ratio = 0.8; Data_size = size(Input, 1); % Number of rows Shuffle = randperm(Data_size); % Randomize indices

% Training data Train_Size = round(ratio * Data_size); X_train = Input(Shuffle(1:Train_Size), :); Y_train = Target(Shuffle(1:Train_Size), :);

% Testing data X_test = Input(Shuffle(Train_Size+1:end), :); Y_test = Target(Shuffle(Train_Size+1:end), :);

% Train the model using TreeBagger TreeModel = TreeBagger(200, X_train, Y_train, 'Method', 'classification'); % Model = fitcensemble(X_train, Y_train, 'Method', 'Bag', 'NumLearningCycles', 10);

% Predict using the trained model predictions = predict(TreeModel, X_test);

% Convert predictions to numeric (TreeBagger outputs strings for classification) predictions = str2double(predictions);

% Calculate accuracy accuracy = sum(predictions == Y_test) / numel(Y_test) * 100; fprintf('Model Accuracy: %.2f%%\n', accuracy);

This is our trained model of data set 972 x 24 and when it is trained it gives 95% accuracy not 100% . At first it was 100% when in target data we had only fault type but as we added bus location also in single model of target accuracy drop

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by