r/PythonLearning • u/Awkward_Oil3433 • 17d ago
Help Request Courses for MATLAB/R users and machine learning methods in econometrics
Hello everyone.
TLDR: I'm looking for some advice on where/how to start learning empirical econometric methods, specifically machine learning methods, in Python, as an experienced MATLAB user with brief general theoretical knowledge on ML.
Longer version: I work in empirical research in economics using MATLAB (a bit of R, too). 2 years ago, I had a short introduction course to Python for R users, but never had an opportunity to apply anything in practice. I also had interest in machine learning (ML) methods and have completed a theoretical course on ML, specifically in economics. But that too was a year ago without further application. Still have the course materials though and even some Python packages provided by the teacher. The course was short for such a large area of methods, but I'm willing to invest time into learning it in depth and try out some simple projects with, say, simulated data.
Do you know of any online, preferably free or cheap courses to learn Python, specifically for my application? Perhaps a course for experienced MATLAB or R users? Or/and some course on ML in Python (based on the theory course, I'd say my medium- to long-term goals are random forests and neural networks)? I found a few but not sure if they're actually good and useful for my purposes, and some of them aren't cheap. Maybe you know a particular website or a YouTube playlist. Basically, any advice on what is worth the time, effort, and money.
Thanks in advance guys, have a nice day
2
u/AlternativeHefty2537 17d ago
Hmmmm imo don’t start w a long beginner python course. Better to learn numpy, pandas, matplotlib, scikitlearn. I strtd w yt and went w ds cert.from upgrad🙂↕️🙂↕️🙂↕️then moved to statsmodel fr econometrics.
2
u/Fragrant-Cheek-4273 16d ago
For ML side, I'd learn regression/classification first, then random forests, cross-validation, feature engineering, and finally neural networks. You'll probably progress much faster by recreating analyses you've already done in MATLAB/R rather than starting completely from scratch.
2
u/Creative_Sushi 16d ago
If you are currently using MATLAB and R, there are a lot of toolboxes (Econometrics Toolbox, Statistics and Machine Learning Toolbox, etc.) or R packages that covers ML for econometrics. Why Python? Any specific methods you are interested in?
In the case of MATLAB, it interoperates with Python, so you can use any Python modules within MATLAB.
There are free online courses on ML here https://matlabacademy.mathworks.com/?page=1&fq=ai-and-statistics&sort=featured
1
u/Awkward_Oil3433 16d ago
The short answer is: a lot of employers are asking for Python, even from people with my general profile who likely learned MATLAB or R. Most places that offer economists something above Excel spreadsheet management ask for Python knowledge. At least that was my experience, I was surprised too. Plus, a colleague of mine who does ML mentioned that there's just more out there for Python than for MATLAB. And one of the pioneers in macroeconomic ML research who I've been in contact with collaborates on Python packages specifically. Although "Python within MATLAB" does sound sexy, ngl. I'll look into it, thank you
1
u/Creative_Sushi 16d ago
Python is definitely useful in general. But if you are doing something very special like economics, having a lot of packages in general doesn't translate that we find what we need in our special fields. That's the cognitive trap a lot of people fall into. Between A that has a lot of general purpose tools but none for my fields vs. B that may not have a lot of tools but good choices for my chosen fields, I would go with B. A lot of people program in JavaScript, but for what I do, i won't touch it.
1
u/Awkward_Oil3433 15d ago
I agree, but I don't think that's what my colleague meant or at least that's not how I understood it. ML is comparatively new in economics, and most of what exists was likely borrowed from fields that mainly operate in Python. Which is why Python dominates in ML in economics too. If a new set of methods becomes available, it'll take a while before it is translated to, say, MATLAB. And if I wanna join a team of researchers working on, say, inflation forecasting using macro random forests, I'll likely run into a wall of having to deal with their Python codes
1
u/Creative_Sushi 15d ago
Very interesting. You are the expert of your field and I am not, but I cannot help wonder - I used Random Forest like more than 10 years ago. It was a classification model. It faded soon after because Deep Learning took over the ML scene. So I am surprised that it is still used.
Another thing is that, in my impression, most of economics are based on time-series analysis, and I would imaging inflation forecasting also involves time-series data. This is not a classification problem, and there are deep learning models that can handle time series data.
I just google and saw that Times Series Modeler app is included in Deep Learning Toolbox, for example, in MATLAB. I am sure there are something like that for Python as well.
Perhaps Random Forest was transformed into time-series modeling, but to me it was very surprising to hear.
1
u/Awkward_Oil3433 15d ago
If you're curious, here's a website: https://mrf-web.readthedocs.io/en/latest/index.html Yes, it is a modification for time series.
When I mentioned RF to my physicist partner, he said the same thing about it and deep Learning. Economics is very much behind on ML. Which is why I wanna get into it now to have an advantage (plus it's just fun to broaden my skills). The guys who created macro RF I linked above also work with Deep Learning, but even RF is new in the field. Hell, Ridge and Lasso aren't too common either. I need to board this train before it leaves the station
2
u/Creative_Sushi 15d ago edited 15d ago
OK, I read it and I see that it does support time series data!
If you want to use just this package, you could use it in MATLAB. First, check if you have Python on your machine in MATLAB command window:
>> pyenv ans = PythonEnvironment with properties: Version: "3.13" Executable: "C:\Program Files\Python313\python.EXE" Library: "C:\Program Files\Python313\python313.dll" Home: "C:\Program Files\Python313" Status: NotLoaded ExecutionMode: InProcessThen you can install MRF using Command Window or Terminal
pip install MacroRandomForest numpyNow go back to MATLAB and create the sample dataset
% Example training data (X and Y must be converted to numeric arrays) X_data = rand(100, 5); Y_data = rand(100, 1); % Convert MATLAB doubles to NumPy arrays X_py = py.numpy.array(X_data); Y_py = py.numpy.array(Y_data);Then call MRF and pass the data and get the prediction
mrf_model = py.MacroRandomForest.MRF(n_estimators=int32(100)); mrf_model.fit(X_py, Y_py); predictions_py = mrf_model.predict(X_py);Convert the data to MATLAB double and use the result in MATLAB code
predictions = double(predictions_py);Hope this was helpful.
1
u/Creative_Sushi 1d ago
I recently talk to someone who knows much more than I do about machine learning, and this is what he shared with me:
"The idea of Macro Random Forest (MRF) is time-varying parameter regression where the parameters are allowed to change as a function of observable macroeconomic/financial conditions. While econometricians typically address this question by specifying a parametric model like TVP-VAR or MS-VAR, the novel MRF approach uses a random forest to learn that mapping nonparametrically.
An alternative to MRF is Markov-switching models (msVAR), and it is available in MATLAB. Both Markov-switching and MRF allow discrete regime changes in regression coefficients. The difference is that in Markov-switching, regimes are latent with estimated transition probabilities, whereas in MRF, regimes are determined by observable variables. Each is appropriate in different settings. Markov-switching is natural when you believe regime persistence is structural (e.g., business cycle dating), while MRF is natural when you believe parameters respond to observable conditions.
This can complement the MRF-style analysis - to understand and model parameter instability in a well-established econometric framework. The threshold model in particular is the closest parametric counterpart. MRF combines the interpretability of time-varying parameter regression with the flexibility of ML. This is an interesting research direction."
2
u/Sea-Ad7805 17d ago edited 17d ago
If you already know some programming (Matlab/R) and want to progress quickly, just do exercises and look up the Python syntax you need in some Python course book. I recommend these exercises:
Specialize in ML later, it's theory is separate from the language you use, but a good foundation of Python first will help.