Issues on the translation of MATLAB machine learning model to Python
12 次查看(过去 30 天)
显示 更早的评论
Dear community,
I had training a Machine Learning model using the classification learner, that as the following characteristics:
% This code specifies all the classifier options and trains the classifier.
template = templateTree(...
'MaxNumSplits', 5003);
classificationEnsemble = fitcensemble(...
predictors, ...
response, ...
'Method', 'Bag', ...
'NumLearningCycles', 30, ...
'Learners', template, ...
'ClassNames', [1; 2; 3; 4; 5]);
I managed to get an accuracy of around 98%.
But when I tried to translate this code to Python, as follows and with the same training set, but I am not able to find the same accuracy, its a lot lower in Python. I would like to know if and what are the differences between both languages so I can adjust the parameters accordingly.
template = templateTree(...
'MaxNumSplits', 5003);
classificationEnsemble = fitcensemble(...
predictors, ...
response, ...
'Method', 'Bag', ...
'NumLearningCycles', 30, ...
'Learners', template, ...
'ClassNames', [1; 2; 3; 4; 5]);
Thank you in advance.
0 个评论
回答(1 个)
Hornett
2024-9-11
When translating machine learning models from MATLAB to Python, there are several factors that can lead to differences in performance. These factors include differences in the default parameters, random state initialization, and implementation details of the algorithms in the respective libraries.
In MATLAB, you used the fitcensemble function with a bagging method and a decision tree template. In Python, you can achieve a similar model using the BaggingClassifier from scikit-learn.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Classification Ensembles 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!