Can I create an array of classification models?

3 vues (au cours des 30 derniers jours)
Dejun Qi
Dejun Qi le 24 Fév 2016
I would like to use a loop to obtain an array of classification models, and then loop through this array, using this trained model one by one to make classification. Can I do that?
For example: I was working on SVM problems and doing the following things:
for i = 1: 6
mds(i) = fitcsvm(X, y, 'Standardize',true, 'KernelFunction', 'linear', 'boxconstraint', C, 'ClassNames', [0, 1]) ;
end
I got error "You cannot assign to an object of class double using () indexing."

Réponses (1)

Shivam Chaturvedi
Shivam Chaturvedi le 29 Fév 2016
Hi Dejun,
As this is an object, there are 2 methods that you can try to make an array of the model object:
1. Append the new object to an existing list
ex:
models = [];
for i=1:6
thisModel = fitcsvm(...);
models = [models thisModel];
end
This will concatenate the 'thisModel' variable every time to the list giving you an array of models.
2. Use a cell array
For this, you would just need to replace
mds(i)
to
mds{i}
This should work ideally in its own. You can also initialize mds as:
mds = {}
before the start of the loop.

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by