This repository contains a toy project for forecasting macroeconomic variables (e.g., CPI-based inflation) using an LSTM in PyTorch. It includes TensorBoard logging for visualization, and fetches data from FRED via pandas_datareader.
- Prerequisites
- Installation Using Miniconda (Recommended on Windows)
- Usage
- Running TensorBoard
- Common Issues and Troubleshooting
- License
- Miniconda (or Anaconda) on Windows, macOS, or Linux.
- Basic familiarity with Python, PyTorch, and Git.
If you prefer a plain Python installation without Conda, you must manually manage your environment and ensure all dependencies are installed (PyTorch, pandas, numpy, etc.). Using Conda simplifies environment management and avoids version conflicts.
- Download Miniconda for your platform from:
https://docs.conda.io/en/latest/miniconda.html - For Windows, choose “Windows 64-bit” (the default on most modern systems).
- Double-click to install, following the prompts. You can keep the default settings.
- On Windows, open your Start Menu and look for "Miniconda Prompt" (or "Anaconda Prompt").
- This special prompt ensures
condais recognized.
- If you have Git installed, open the Miniconda Prompt and run:
git clone https://github.com/YOUR_USERNAME/YOUR_REPO.git cd YOUR_REPO
- Or download the repo as a ZIP from GitHub and extract it, then
cdinto the unzipped folder in the Miniconda Prompt:cd path\to\YOUR_REPO
conda create -n macroRL python=3.10
conda activate macroRL- This creates an environment named
macroRLwith Python 3.10. - Adjust the Python version if you wish (e.g.
3.9,3.11).
-
CPU-Only PyTorch (simplest if you don’t need GPU):
conda install pytorch torchvision torchaudio cpuonly -c pytorch -
NVIDIA GPU + CUDA (for faster training):
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
This automatically installs CUDA 11.8 support with PyTorch.
-
Other libraries:
conda install pandas numpy pandas-datareader pip install tensorboard(Optionally add
conda install matplotlibif you want local plots.)
- Check Python:
python --version - Check PyTorch version:
python -c "import torch; print(torch.__version__)"
- Check TensorBoard import:
python -c "import tensorboard"
If these commands run without errors, you’re set.
-
Activate the Environment
In a new terminal (Miniconda Prompt):conda activate macroRL
Then navigate to the project folder:
cd path\to\YOUR_REPO
-
Run the Training Script
python main.py
- This script will:
- Fetch CPI data from FRED (via
pandas_datareader). - Compute year-over-year inflation.
- Train an LSTM model in PyTorch.
- Log metrics (loss, RMSE, etc.) and plots to TensorBoard in a
runs/directory.
- Fetch CPI data from FRED (via
- This script will:
-
(Optional) Adjust Hyperparameters
- Open
main.pyand change parameters likeEPOCHS,LOOKBACK, or the LSTMhidden_size. - Rerun
python main.pyto see how it affects training.
- Open
To view logs in real-time or after training completes:
conda activate macroRL
cd path\to\YOUR_REPO
tensorboard --logdir=runs --port=6006If tensorboard isn’t recognized, try:
python -m tensorboard --logdir=runs --port=6006Open http://localhost:6006 in your browser.
You’ll see:
- Scalars: Training/validation losses, RMSE, MAE across epochs
- Figures: Plots of actual vs. predicted inflation (if your script logs them)
- Graphs: High-level model graph (optional)
-
conda: command not foundor “Term 'conda' is not recognized”- On Windows, ensure you’re in the Miniconda Prompt (Start Menu → “Miniconda3 Prompt”) or have run
conda init powershellso that conda is recognized in your shell. - Restart your terminal/PowerShell if changes have been made to PATH.
- On Windows, ensure you’re in the Miniconda Prompt (Start Menu → “Miniconda3 Prompt”) or have run
-
No module named tensorboardor “tensorboard not recognized”**- Install TensorBoard again with:
conda activate macroRL pip install tensorboard
- Or run with
python -m tensorboard --logdir=runs. - Confirm you’re in the correct conda environment.
- Install TensorBoard again with:
-
FRED Data Access Problems
- If
pandas_datareadercannot fetch data due to rate limits, you may need an API key. See FRED API docs. - Or manually download a CSV from FRED and load it in
main.pyinstead.
- If
-
GPU Not Detected
- Check if your GPU is recognized by PyTorch:
python -c "import torch; print(torch.cuda.is_available())"
- If
False, ensure you installed the GPU version (pytorch-cuda=11.8) and have compatible NVIDIA drivers. - Make sure your script sets
DEVICE = "cuda"(iftorch.cuda.is_available()returns True).
- Check if your GPU is recognized by PyTorch:
This project is licensed under the MIT License - see the LICENSE file for details.