Can I create an array of classification models?

4 visualizzazioni (ultimi 30 giorni)
Dejun Qi
Dejun Qi il 24 Feb 2016
Risposto: Shivam Chaturvedi il 29 Feb 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."

Risposte (1)

Shivam Chaturvedi
Shivam Chaturvedi il 29 Feb 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.

Categorie

Scopri di più su Statistics and Machine Learning Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by