Can I create an array of classification models?
3 ビュー (過去 30 日間)
古いコメントを表示
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."
0 件のコメント
回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File 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!