Skip to content

Commit

Permalink
ClassificationPartitionedModel: add input validation for cvpartition …
Browse files Browse the repository at this point in the history
…object, issue #160
  • Loading branch information
pr0m1th3as committed Sep 10, 2024
1 parent dcbf162 commit 8a992e3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion inst/Classification/ClassificationPartitionedModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,19 @@
error ("ClassificationPartitionedModel: too few input arguments.");
endif

## Check for valid object types
## Check for valid Classification object
validTypes = {'ClassificationDiscriminant', 'ClassificationGAM', ...
'ClassificationKNN', 'ClassificationNeuralNetwork', ...
'ClassificationSVM'};
if (! any (strcmp (class (Mdl), validTypes)))
error ("ClassificationPartitionedModel: unsupported model type.");
endif

## Check for valid cvpartition object
if (! strcmp (class (Partition), "cvpartition"))
error ("ClassificationPartitionedModel: invalid 'cvpartition' object.");
endif

## Set properties
this.X = Mdl.X;
this.Y = Mdl.Y;
Expand Down Expand Up @@ -670,6 +675,9 @@
%!error<ClassificationPartitionedModel: unsupported model type.> ...
%! ClassificationPartitionedModel (RegressionGAM (ones (40,2), ...
%! randi ([1, 2], 40, 1)), cvpartition (randi ([1, 2], 40, 1), 'Holdout', 0.3))
%!error<ClassificationPartitionedModel: invalid 'cvpartition' object.> ...
%! ClassificationPartitionedModel (ClassificationKNN (ones (4,2), ...
%! ones (4,1)), 'Holdout')

## Test for kfoldPredict
%!test
Expand Down

0 comments on commit 8a992e3

Please sign in to comment.