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

3 views (last 30 days)
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!

Answers (1)

Walter Roberson
Walter Roberson on 21 Sep 2022
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 Comments
Walter Roberson
Walter Roberson on 21 Sep 2022
Edited: Walter Roberson on 26 Sep 2022
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 on 26 Sep 2022
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?

Sign in to comment.

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!