How to use for loops for hyperparameter tuning using fitcnb

2 visualizaciones (últimos 30 días)
Catherine Branter
Catherine Branter el 12 de Nov. de 2018
Editada: madhan ravi el 21 de Nov. de 2018
I have different types of distribution I want to test for my fitcnb Naive Bayes model to see which is the bestand I'm running into an error
My code is:
%Set different types of distribution dist_1= {'kernel','mvmn','mvmn','kernel','mvmn','mvmn','mvmn','mvmn','mvmn'}; dist_2= {'normal','mvmn','mvmn','normal','mvmn','mvmn','mvmn','mvmn','mvmn'}; dist_3= {'kernel','mvmn','mvmn','normal','mvmn','mvmn','mvmn','mvmn','mvmn'}; dist_4={'normal','mvmn','mvmn','kernel','mvmn','mvmn','mvmn','mvmn','mvmn'}; distributionoptions = [dist_1 dist_2 dist_3 dist_4];
for d = distributionoptions MdlA = fitcnb(Xtrain,Ytrain,'ClassNames', class_names,'Crossval',{'Off'},'DistributionNames',d); end
The error I get is Error using classreg.learning.modelparams.NaiveBayesParams/checkDistributionNames (line 91) 'DistributionNames' value must be a character vector or string scalar, or a string array or cell array whose length equals the number of predictors.

Respuestas (1)

Don Mathis
Don Mathis el 15 de Nov. de 2018
I think you accidentally concatenated your cell arrays together. Instead use curly braces:
distributionoptions = {dist_1 dist_2 dist_3 dist_4};
After that, inside the loop, d will be a 1x1 cell array, so you need to do d{1} in there:
for d = distributionoptions
MdlA = fitcnb(Xtrain,Ytrain,'ClassNames', class_names,'Crossval',{'Off'},'DistributionNames',d{1});
end

Community Treasure Hunt

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

Start Hunting!

Translated by