Bayesian Methods for Hackers - Deployment and Usage Guide
Prerequisites
- Python 3.x (recommended: Python 3.7 or higher)
- Jupyter Notebook or JupyterLab for running the notebooks
- PyMC2 (the probabilistic programming library used in this book)
- NumPy (required dependency)
- SciPy (optional dependency)
- Matplotlib (for visualization)
- Git (for cloning the repository)
Installation
-
Clone the repository:
git clone https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers.git cd Probabilistic-Programming-and-Bayesian-Methods-for-Hackers -
Create a virtual environment (recommended):
python -m venv bayesian_env source bayesian_env/bin/activate # On Windows: bayesian_env\Scripts\activate -
Install dependencies:
pip install pymc numpy scipy matplotlib jupyter -
Install Jupyter Notebook (if not already installed):
pip install notebook
Configuration
No specific configuration files or API keys are required for this project. The notebooks are self-contained and use only the installed Python packages.
Build & Run
Running Locally (Development)
-
Start Jupyter Notebook:
jupyter notebook -
Navigate to the cloned repository in your browser and open any of the notebook files (e.g.,
Chapter1_Introduction/Ch1_Introduction_PyMC2.ipynb). -
Run the notebooks by clicking "Run" or pressing Shift+Enter to execute each cell.
Running Locally (Production)
Since this is an educational resource of Jupyter notebooks, there is no traditional "production" deployment. The notebooks can be viewed and executed locally as described above.
Deployment
This project is designed to be run locally as Jupyter notebooks. However, if you want to share the notebooks online, consider these options:
-
GitHub Pages with nbviewer:
- Push your repository to GitHub
- Use the nbviewer link format:
http://nbviewer.jupyter.org/github/yourusername/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/blob/master/Chapter1_Introduction/Ch1_Introduction_PyMC2.ipynb
-
Google Colab:
- Upload the notebooks to Google Drive
- Open them with Google Colab for cloud-based execution
-
Binder:
- Create a Binder environment from your repository
- Users can run notebooks interactively in their browser
Troubleshooting
Common Issues and Solutions
-
ImportError: No module named 'pymc'
- Solution: Ensure PyMC2 is installed with
pip install pymc - Note: PyMC2 is the version used in this book. PyMC3/PyMC4 are newer versions with different APIs.
- Solution: Ensure PyMC2 is installed with
-
ModuleNotFoundError: No module named 'numpy'
- Solution: Install NumPy with
pip install numpy
- Solution: Install NumPy with
-
Jupyter Notebook won't start
- Solution: Ensure Jupyter is installed with
pip install notebook - Check if the virtual environment is activated
- Solution: Ensure Jupyter is installed with
-
Notebooks not rendering properly
- Solution: Try using
jupyter labinstead ofjupyter notebook - Ensure all dependencies are installed and up to date
- Solution: Try using
-
Performance issues with large datasets
- Solution: Consider using PyMC3 or PyMC4 (newer versions with better performance)
- Upgrade hardware if working with very large datasets
-
Compatibility issues with newer Python versions
- Solution: Use Python 3.7 or 3.8 for best compatibility with PyMC2
- Consider creating a conda environment with specific Python version
Additional Notes
- The book uses PyMC2, which is an older version of PyMC. If you're familiar with PyMC3 or PyMC4, note that the API has changed significantly.
- For the most up-to-date examples and explanations, visit the project homepage.
- The printed version includes additional content like a chapter on Bayesian A/B testing and answers to end-of-chapter questions.