필터 지우기
필터 지우기

Hierarchical classification with two models

조회 수: 7 (최근 30일)
Supriya Gain
Supriya Gain 2022년 7월 26일
답변: Shantanu Dixit 2024년 9월 9일 10:23
I haved 2 classification models. In 1st model I can classify between class 1 and class 2. Now from class 2 I want to classify class 3 and class 4 with model 2. How can I do that in matlab. pls help

답변 (1개)

Shantanu Dixit
Shantanu Dixit 2024년 9월 9일 10:23
Hi Supriya, hierarchical classification with two models can be done given we have ground truth data for both classes 3 and 4. Without the ground truth for classes 3 and 4 it is not possible to train or validate the second classifier.
  • Train two models: Train two separate models to classify between classes 1,2 and classes 3,4 respectively.
  • Classification step: Using model 1 make predictions and classify input data into either class 1 or class 2. For the data points classified as class 2, use model 2 to further classify them into class 3 and class 4 using model 2.
Here's a high level implementation of the above steps (assuming pre-trained models 1 and 2)
% Assume you have trained classifiers 'model1' and 'model2'
% Input data - X (e.g., feature matrix X)
pred_model1 = predict(model1, X); % (class 1 vs class 2) using model 1
% Find instances classified as class 2
class2_indices = find(pred_model1 == 2);
% Classify these instances using model 2
if ~isempty(class2_indices)
X_class2 = X(class2_indices, :); % Extract features for class 2
pred_model2 = predict(model2, X_class2); % Classify into class 3 or 4
pred_model1(class2_indices) = pred_model2 + 2; % Add 2 to shift to class 3 or 4
end
% pred_model1 now contains class 1, 3, and 4
Refer to the 'predict' function in MATLAB for more information:

카테고리

Help CenterFile Exchange에서 Classification Ensembles에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by