Undefined function 'round' for input arguments of type 'categorical' error

Hello experts,
I was trying to perform the example of function fitclinear described in the matlab help documentation, and I got an error.
Here is the described the example:
load nlpdata
X = X';
Ystats = Y == 'stats';
rng default
Mdl = fitclinear(X,Ystats,'ObservationsIn','columns','Solver','sparsa',...
'OptimizeHyperparameters','auto','HyperparameterOptimizationOptions',...
struct('AcquisitionFunctionName','expected-improvement-plus'))
Here the error that I got:
Undefined function 'round' for input arguments of type 'categorical'.
Error in iscategorical (line 26)
if size(mat, 1) == 1 && all(round(mat) == mat)
Error in classreg.learning.paramoptim.prepareArgValue (line 12)
elseif iscategorical(elt)
Error in classreg.learning.paramoptim.BayesoptInfo.argsFromTable (line 151)
classreg.learning.paramoptim.prepareArgValue(XTable{1,v})}];
Error in classreg.learning.paramoptim.BayesoptInfo/updateArgsFromTable (line 56)
ArgsFromTable = classreg.learning.paramoptim.BayesoptInfo.argsFromTable(XTable);
Error in classreg.learning.paramoptim.createObjFcn/theObjFcn (line 17)
NewFitFunctionArgs = updateArgsFromTable(BOInfo, FitFunctionArgs, XTable);
Error in BayesianOptimization/callObjNormally (line 2184)
Objective = this.ObjectiveFcn(conditionalizeX(this, X));
Error in BayesianOptimization/callObjFcn (line 2145)
= callObjNormally(this, X);
Error in BayesianOptimization/performFcnEval (line 2128)
ObjectiveFcnObjectiveEvaluationTime, this] = callObjFcn(this, this.XNext);
Error in BayesianOptimization/run (line 1836)
this = performFcnEval(this);
Error in BayesianOptimization (line 450)
this = run(this);
Error in bayesopt (line 287)
Results = BayesianOptimization(Options);
Error in classreg.learning.paramoptim.fitoptimizing>doBayesianOptimization (line 182)
OptimizationResults = bayesopt(objFcn, VariableDescriptions, ...
Error in classreg.learning.paramoptim.fitoptimizing (line 136)
[OptimizationResults, XBest] = doBayesianOptimization(objFcn, BOInfo, VariableDescriptions,
HyperparameterOptimizationOptions);
Error in fitclinear (line 218)
[varargout{1:nargout}] = classreg.learning.paramoptim.fitoptimizing('fitclinear',X,y,varargin{:});
Any suggestions will be helpful.
Thanks

5 件のコメント

dpb
dpb 2019 年 5 月 26 日
What does
whos X
return? categorical class, I presume?
Try
Mdl = fitclinear(double(X),Ystats,'ObservationsIn','columns','Solver','sparsa',...
...
instead and see if joy ensues. It surely is an irritation when examples don't work either because they simply were pasted in from non-working code or TMW has made changes in other routines that may have been allowable in earlier versions and no longer are.
Walter Roberson
Walter Roberson 2019 年 5 月 27 日
I did not encounter this problem when I tested in R2019a on my Mac.
Walter Roberson
Walter Roberson 2019 年 5 月 27 日
What shows up for
which -all iscategorical
The main iscategorical() routine is quite short. The one for classreg.learning.internal.ClassLabel does not have any round() in it, at least in R2019a.
dpb
dpb 2019 年 5 月 27 日
編集済み: dpb 2019 年 5 月 27 日
With R2017b it errors...my R2018b install got blown away by a Window update and haven't had the time to reinstall it...so, it's probably from OP looking at new doc and running older release.
My matlab version is R2017a.
>> whos X
Name Size Bytes Class Attributes
X 34023x31572 36696696 double sparse
>> which -all iscategorical
G:\1master courses\semester 2\2015_Advances in brain imaging\software\princeton-mvpa-toolbox-master\core\util\iscategorical.m
D:\Program Files\MATLAB\R2017a\toolbox\distcomp\parallel\@codistributed\iscategorical.m % codistributed method
D:\Program Files\MATLAB\R2017a\toolbox\stats\classreg\+classreg\+learning\+internal\ClassLabel.m % classreg.learning.internal.ClassLabel method
D:\Program Files\MATLAB\R2017a\toolbox\matlab\datatypes\iscategorical.m % Shadowed
I also tried double(X)
>> Mdl = fitclinear(double(X),Ystats,'ObservationsIn','columns','Solver','sparsa',...
'OptimizeHyperparameters','auto','HyperparameterOptimizationOptions',...
struct('AcquisitionFunctionName','expected-improvement-plus'))
Undefined function 'round' for input arguments of type 'categorical'.
Error in iscategorical (line 26)
if size(mat, 1) == 1 && all(round(mat) == mat)

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2019 年 5 月 27 日

0 投票

Your Advances in Brain Imaging software is interfering. Use pathtool to move that course to the bottom.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Data Type Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by