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 日

1 投票

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 件)

カテゴリ

タグ

質問済み:

2025 年 3 月 4 日

コメント済み:

2025 年 3 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by