Clear Filters
Clear Filters

Stacking implementation of 2 neural nets

5 views (last 30 days)
yogini prabhu
yogini prabhu on 8 Jul 2022
Answered: Akshat on 1 Sep 2023
  • Stacking is an ensemble machine learning algorithm that learns how to best combine the predictions from multiple well-performing machine learning models.
so if I use patternnet or lvqnet to create 2 separate net models in the following case : 2 factors of one being ( eg 1: - heart rate and blood profile : which are to be utilised into 1 single decision to decide cholesterol profile of patient, eg 2:- leaf spectra and bark spectra of a single tree : which are to be utilised for its stress diagnosis) .
so then how to stack the 2 nets as per ensemble modeling using Matlab?

Answers (1)

Akshat
Akshat on 1 Sep 2023
Hi Yogini,
As per what I understand, stacking can be done with two or more machine learning models to make one ensemble model, which outperforms (usually) the models constituting it.
The catch here is, those models are trained on the same training set, but as you mentioned in the question, you will train one neural net on heart rate and the other on blood profile. I am not exactly sure if this will work, as the data used to train isn’t consistent for both the models (even when the dimensions are consistent).
In case you want to stack two models trained on the same dataset, you can follow the steps mentioned in this documentation page:
This is where the documentation made the base models:
% SVM with Gaussian kernel
rng('default') % For reproducibility
mdls{1} = fitcsvm(adultdata,'salary','KernelFunction','gaussian', ...
'Standardize',true,'KernelScale','auto');
% SVM with polynomial kernel
rng('default')
mdls{2} = fitcsvm(adultdata,'salary','KernelFunction','polynomial', ...
'Standardize',true,'KernelScale','auto');
% Decision tree
rng('default')
mdls{3} = fitctree(adultdata,'salary');
% Naive Bayes
rng('default')
mdls{4} = fitcnb(adultdata,'salary');
% Ensemble of decision trees
rng('default')
mdls{5} = fitcensemble(adultdata,'salary');
Following is how you stack the models:
rng('default') % For reproducibility
N = numel(mdls);
Scores = zeros(size(adultdata,1),N);
cv = cvpartition(adultdata.salary,"KFold",5);
for ii = 1:N
m = crossval(mdls{ii},'cvpartition',cv);
[~,s] = kfoldPredict(m);
Scores(:,ii) = s(:,m.ClassNames=='<=50K');
end

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!