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

4 次查看(过去 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 中查找有关 Run on Android Device 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by