Day 2: Setting Up Environment
π Table of Contents
- π Welcome to Day 2
- π₯οΈ Installing Python and Dependencies
- Python Installation
- Package Managers (pip, conda)
- Virtual Environments
- π§ Setting Up Your Machine Learning Workspace
- Anaconda Distribution
- Miniconda
- Using Requirements Files
- π» IDEs and Editors
- VS Code
- PyCharm
- Jupyter Notebook
- π Organizing Your Projects
- Directory Structure
- Version Control (Git)
- 𧩠Hands-On Exercises
- π Resources
- π‘ Tips and Tricks
1. π Welcome to Day 2
Welcome to Day 2 of your journey to becoming a Scikit-Learn Boss in 90 Days! π Todayβs focus is on setting up a clean and efficient environment for your machine learning projects. A well-structured environment ensures smoother development, reproducibility, and maintains consistency across projects. Letβs get everything ready to tackle advanced concepts in the days ahead! π
2. π₯οΈ Installing Python and Dependencies
π Python Installation
- Official Python Website: Download and install the latest stable version of Python from python.org.
- Check Installation:
python3 --version
π Package Managers (pip, conda)
- pip: The default Python package manager.
pip install numpy pandas scikit-learn
- conda: An environment and dependency manager that comes with Anaconda or Miniconda.
conda install numpy pandas scikit-learn
π Virtual Environments
- Creation:
python3 -m venv my_env
- Activation:
- Linux/MacOS:
source my_env/bin/activate
- Windows:
my_env\Scripts\activate
- Linux/MacOS:
- Deactivation:
deactivate
3. π§ Setting Up Your Machine Learning Workspace
π Anaconda Distribution
- All-In-One Package: Comes pre-installed with Python, Jupyter, and popular data science libraries.
- Installation: Download from anaconda.com and follow the setup instructions.
π Miniconda
- Lightweight Alternative: Provides a minimal environment and conda for managing packages and environments.
- Installation: Download from docs.conda.io.
π Using Requirements Files
- requirements.txt:
pip install -r requirements.txt
- environment.yml (for conda):
conda env create -f environment.yml
4. π» IDEs and Editors
π VS Code
- Extensions: Python, Jupyter, Pylance.
- Integrated Terminal: Manage environments and run Python files directly.
π PyCharm
- Professional Environment: Robust tools for testing, debugging, and refactoring.
- Integrated Tools: Virtual environment setup and version control within the IDE.
π Jupyter Notebook
- Interactive Environment: Perfect for exploration, experimentation, and quick prototyping.
- Run in Browser:
jupyter notebook
5. π Organizing Your Projects
π Directory Structure
- Example:
project_name/ data/ notebooks/ src/ tests/ README.md requirements.txt
π Version Control (Git)
- Initialize Repo:
git init
- Commit Changes:
git add . git commit -m "Initial commit"
6. 𧩠Hands-On Exercises
π Exercise 1: Create and Activate a Virtual Environment
- Task: Create a virtual environment named
ml_env
and activate it. Installnumpy
,pandas
, andscikit-learn
inside it.python3 -m venv ml_env source ml_env/bin/activate pip install numpy pandas scikit-learn
π Exercise 2: Set Up a Conda Environment
- Task: Using Anaconda or Miniconda, create a conda environment named
ml_conda_env
with Python 3.9 and installmatplotlib
andseaborn
.conda create --name ml_conda_env python=3.9 conda activate ml_conda_env conda install matplotlib seaborn
π Exercise 3: Start a Jupyter Notebook
- Task: From within your activated environment, start a Jupyter Notebook and verify you can import
sklearn
.jupyter notebook # In a new notebook cell: import sklearn print(sklearn.__version__)
7. π Resources
- Python Official Docs
- Conda Documentation
- Virtualenv Documentation
- PyPI (Python Package Index)
- VS Code Python Extension
- Git Documentation
8. π‘ Tips and Tricks
π‘ Pro Tip
Isolate Your Projects: Keep separate environments for different projects to avoid dependency conflicts.
π οΈ Recommended Tools
- Poetry: For dependency management and packaging.
- Docker: For containerized, reproducible environments.
π Speed Up Your Setup
- Use Environment Files: Automate environment creation with
requirements.txt
orenvironment.yml
. - Shortcuts:
conda activate
andconda deactivate
for quick environment switching.
π Debugging Setup Issues
- Check PATH: Ensure Python and package managers are on your PATH.
- Reinstall: If issues persist, reinstall Python or Anaconda.
- Community Forums: Leverage Stack Overflow and official docs for troubleshooting.