random forest block in simulink

4 vues (au cours des 30 derniers jours)
insherah
insherah le 4 Mar 2025
Commenté : insherah le 6 Mar 2025

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

Réponse acceptée

aditi bagora
aditi bagora le 6 Mar 2025
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 commentaire
insherah
insherah le 6 Mar 2025

% %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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Deep Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by