# Day 1: Create a Python Virtual Environment for ML

Welcome to Day 1 of your 100 Days of ML challenge! 

Since you are starting as a beginner and want to do everything manually, let's break down exactly what a Virtual Environment is, why we need it, and how to set it up locally on your Windows machine.

## 🧠 What is a Virtual Environment?
Imagine you are building two different Lego projects. One requires only red pieces, and the other requires only blue pieces. If you mix all the pieces in one big box, it becomes messy to find what you need. 

In Python, different Machine Learning projects often require different versions of libraries (like different sizes or colors of Lego blocks). If we install everything globally on your computer, projects might conflict with each other. A **Virtual Environment** is like creating a separate, dedicated Lego box for a single project.

Here is a visual representation of how Virtual Environments protect your system:

```mermaid
mindmap
  root((Your Computer))
    System_Python[Global Python Installation]
      System_Packages[System-wide packages]
        Conflicts(Version Conflicts!)
    Project_A[Project A Folder]
      Venv_A((ml-env A))
        Pandas_1[Pandas v1.0]
        Numpy_1[Numpy v1.18]
    Project_B[Project B Folder]
      Venv_B((ml-env B))
        Pandas_2[Pandas v2.2]
        Numpy_2[Numpy v1.26]
```

---

## 🛠️ Prerequisites: Checking your Python Installation
Before we begin, you need to make sure Python is installed on your local Windows machine. 

1. Open your **PowerShell** or **Command Prompt**.
2. Type the following command and press Enter:
   ```bash
   python --version
   ```
   **Expected Output:**
   ```text
   Python 3.11.4
   ```
   *(Your version number might differ. If it says "command not found", you need to download Python from [python.org](https://www.python.org/downloads/).)*

---

## 🎯 Task 1: Create the Virtual Environment
The KodeKloud task asks you to create an environment named `ml-env` under `/root/code/`. Since you are practicing locally, we'll create it in your current folder.

### Step-by-step:
1. Open your PowerShell and navigate to your project folder:
   ```powershell
   cd C:\Users\HP\Documents\Learning-Content\100-days-ML-challenge
   ```
2. Run the following command to create the virtual environment:
   ```powershell
   python -m venv ml-env
   ```
   **Expected Output:**
   *(You won't see any text output! The terminal will just pause for a second and return to the prompt. If you type `dir`, you will see a new folder named `ml-env` has been created.)*

   **Explanation of the command:**
   * `python`: Calls the Python program.
   * `-m venv`: Tells Python to run the built-in `venv` module.
   * `ml-env`: The name of the folder being created.

---

## 🎯 Task 2: Activate the Environment and Install Packages
Right now, the environment exists, but your terminal isn't using it yet. We need to **activate** it.

### Step-by-step (Windows):
1. In your PowerShell, run the activation script:
   ```powershell
   .\ml-env\Scripts\activate
   ```
   **Expected Output:**
   ```text
   (ml-env) PS C:\Users\HP\Documents\Learning-Content\100-days-ML-challenge>
   ```
   *(Notice the `(ml-env)` prefix! This proves you are inside the bubble.)*

### Installing the ML Libraries:
Now, let's install the fundamental Machine Learning libraries.

1. Run the following command:
   ```powershell
   pip install numpy pandas scikit-learn matplotlib
   ```
   **Expected Output:**
   ```text
   Collecting numpy
     Downloading numpy-1.26.4-cp311-cp311-win_amd64.whl (15.8 MB)
   Collecting pandas
     Downloading pandas-2.2.1-cp311-cp311-win_amd64.whl (11.6 MB)
   ...
   Successfully installed matplotlib-3.8.3 numpy-1.26.4 pandas-2.2.1 scikit-learn-1.4.1
   ```

---

## 🎯 Task 3: Generate a `requirements.txt` file
When you share code, you need to tell others exactly which libraries your project needs. We do this with a `requirements.txt` file.

### Step-by-step:
1. Run the following command:
   ```powershell
   pip freeze > requirements.txt
   ```
   **Expected Output:**
   *(Again, no output on the screen because the `>` symbol redirected it all into the file.)*

2. Verify the file contents:
   ```powershell
   cat requirements.txt
   ```
   **Expected Output:**
   ```text
   contourpy==1.2.0
   cycler==0.12.1
   fonttools==4.50.0
   joblib==1.3.2
   kiwisolver==1.4.5
   matplotlib==3.8.3
   numpy==1.26.4
   pandas==2.2.1
   Pillow==10.2.0
   pyparsing==3.1.2
   python-dateutil==2.9.0.post0
   pytz==2024.1
   scikit-learn==1.4.1
   scipy==1.12.0
   six==1.16.0
   threadpoolctl==3.3.0
   tzdata==2024.1
   ```
   *(Notice how `pip` automatically installed dependencies of dependencies, like `joblib` and `tzdata`!)*

---

## 🏁 Wrap Up
To step out of your virtual environment, simply type:
```powershell
deactivate
```
**Expected Output:** The `(ml-env)` prefix will disappear from your terminal.

**Are you ready to move on to Day 2?**
