Can I create an array of classification models?

조회 수: 3 (최근 30일)
Dejun Qi
Dejun Qi 2016년 2월 24일
답변: Shivam Chaturvedi 2016년 2월 29일
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."

답변 (1개)

Shivam Chaturvedi
Shivam Chaturvedi 2016년 2월 29일
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.

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by