MATLAB vs Python sklearn ML models - different results

조회 수: 4 (최근 30일)
Jenni Liu
Jenni Liu 2022년 10월 9일
댓글: AR 2022년 10월 10일
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
AR
AR 2022년 10월 10일
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

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by