MATLAB vs Python sklearn ML models - different results
4 views (last 30 days)
Show older comments
Hello Mathworks community,
I am working on a script that I am translating from MATLAB to Python (Jupyter Notebooks). After reading in and prepocessing data inputs, I compute my X and Y data arrays that I want to feed into the train_test_split function. Then, I train my model (Random Forest regressor) using the training data and check how capabel my model is by checking predictions against test values. In MATLAB, I get correlation values of around 0.65-0.7, which is pretty good considering the data I am using. In Python, the R values are around 0.4-0.5.
The code is 1 to 1 translated (to the best of my abilities). But I am able to replicate the exact same X and Y input arrays from the original MATLAB code in Python, which tells me that my translation is correct so far.
Now my question/issue: Why do I get far worse correlation values using my Python model? It tells me that the Random Forest python equivalent is learning and predicting much worse even though I am technically using the same ML model and feed it the exact same data. Are there fundamental differences between the two platforms that I am not aware of? Or is it normal that different programming languages process ML models differently?
Thank you for your insight!
1 Comment
AR
on 10 Oct 2022
Hi Jenni,
Have you also made sure to use the same parameters for the random forest such as the number of trees, maximum depth, etc? Yet, slight variation in results is expected due to the nature of the algorithm itself - it is stochastic. As a result, a slightly different model is learnt each time it is run.
More information about why you might be getting different results: Why Do I Get Different Results Each Time in Machine Learning? (machinelearningmastery.com)
Thank you
Answers (0)
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!