Error using classreg.l​earning.in​ternal.cla​ssCount (line 31) You passed an unknown class '0.7641' of type double.

조회 수: 5 (최근 30일)
I am trying to run the HAR simulink to android example using the "bag" method instead of "adaboostM2", the lines of codes are as:
load humanactivity
rng('default') %for reproducibility
Partition = cvpartition(actid, 'Holdout', 0.10);
trainingInds = training(Partition); % Indices for training set
XTrain = feat(trainingInds,:);
YTrain = actid(trainingInds);
testInds = test(Partition); % Indices for test set
XTest = feat(testInds,:);
YTest = feat(testInds);
tTrain = array2table([XTrain YTrain]);
tTrain.Properties.VariableNames = [featlabels' 'Activities'];
template = templateTree('MaxNumSplits', 20, 'Reproducible', true);
classificationEnsemble = fitcensemble(XTrain, YTrain,...
'Method', 'bag',...
'NumLearningCycles', 30,...
'Learners', template, ...
'ClassNames',[1;2;3;4;5]);
partitionedModel = crossval(classificationEnsemble, 'KFold', 5);
validationAccuracy = 1-kfoldLoss(partitionedModel)
testAccuracy = 1-loss(classificationEnsemble,XTest,YTest)
I am getting the following errors shile testing:
Error using classreg.learning.internal.classCount (line 31)
You passed an unknown class '0.7641' of type double.
Error in classreg.learning.classif.ClassificationModel/prepareDataForLoss (line 316)
C = classreg.learning.internal.classCount(this.ClassSummary.ClassNames,Y);
Error in classreg.learning.classif.CompactClassificationEnsemble/loss (line 339)
[X,C,W] = prepareDataForLoss(this,X,Y,W,[],true,true);
Error in HAR (line 33)
testAccuracy = 1-loss(classificationEnsemble,XTest,YTest)
Please help me debug the code.
Thank you for your time!

답변 (1개)

Walter Roberson
Walter Roberson 2022년 9월 21일
load humanactivity
rng('default') %for reproducibility
Partition = cvpartition(actid, 'Holdout', 0.10);
trainingInds = training(Partition); % Indices for training set
XTrain = feat(trainingInds,:);
YTrain = actid(trainingInds);
testInds = test(Partition); % Indices for test set
XTest = feat(testInds,:);
YTest = actid(testInds); %<---- this was your error
tTrain = array2table([XTrain YTrain]);
tTrain.Properties.VariableNames = [featlabels' 'Activities'];
template = templateTree('MaxNumSplits', 20, 'Reproducible', true);
classificationEnsemble = fitcensemble(XTrain, YTrain,...
'Method', 'bag',...
'NumLearningCycles', 30,...
'Learners', template, ...
'ClassNames',[1;2;3;4;5]);
partitionedModel = crossval(classificationEnsemble, 'KFold', 5);
validationAccuracy = 1-kfoldLoss(partitionedModel)
validationAccuracy = 0.9673
testAccuracy = 1-loss(classificationEnsemble,XTest,YTest)
testAccuracy = 0.9613
  댓글 수: 4
Walter Roberson
Walter Roberson 2022년 9월 21일
편집: Walter Roberson 2022년 9월 26일
fitcensemble() cannot be deployed to Android (or other hardware).
The workflow for deploying classifiers and approximators, is that you have to do the training with a real MATLAB session first, and you save the classification results to a file. Then you create a new project that load()'s the file and arranges input data as appropriate for the hardware, and uses predict() or whichever function is appropriate for the object class. The training portion cannot take place on the deployed hardware, but the results of training can be used on the hardware to classify or approximate.
Doli Hazarika
Doli Hazarika 2022년 9월 26일
I understood that part. My problem is when I am trying to run the simulink model given in "slexHARAndroidExample", then it is showing error in calibration block. The error is given in my above answer. So do I need to remove the calibration block from the simlink diagram so as to run the model to an android app?

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

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by