# Day 2: Set Up and Configure Jupyter Notebook Server

Welcome to Day 2! Now that we have our isolated Python environment from Day 1, it's time to set up the most popular playground for Data Scientists and Machine Learning Engineers: **Jupyter Notebook**.

## 🧠 What is a Jupyter Notebook?
When you write regular Python code (like in a `.py` file), you execute the whole script at once. This is bad for Machine Learning, where you often want to explore data step-by-step, see a graph, tweak a variable, and run just a small chunk of code without starting over.

Jupyter Notebook solves this. It gives you a web-based interface where you can write code in "cells", run them individually, and see outputs (like tables and charts) directly below the code.

Here is how Jupyter works behind the scenes:

```mermaid
flowchart LR
    Browser["🌐 Web Browser<br>(Your Interface)"] <-->|Sends Code / Gets Output| Server["💻 Notebook Server<br>(Runs in Terminal)"]
    Server <-->|Executes Python Code| Kernel["🐍 Python Kernel<br>(Inside ml-env)"]
    
    style Browser fill:#f9f,stroke:#333,stroke-width:2px
    style Server fill:#bbf,stroke:#333,stroke-width:2px
    style Kernel fill:#bfb,stroke:#333,stroke-width:2px
```

---

## 🎯 Task 1: Install Jupyter Notebook
Since Jupyter Notebook is a Python package, we need to install it inside our `ml-env` virtual environment.

### Step-by-step:
1. Open your terminal (PowerShell) and navigate to your challenge folder:
   ```powershell
   cd C:\Users\HP\Documents\Learning-Content\100-days-ML-challenge
   ```
2. **Activate your environment**:
   ```powershell
   .\ml-env\Scripts\activate
   ```
3. Install the `notebook` package:
   ```powershell
   pip install notebook
   ```
   **Expected Output:**
   ```text
   Collecting notebook
     Downloading notebook-7.1.1-py3-none-any.whl (5.0 MB)
   ...
   Successfully installed notebook-7.1.1 ...
   ```
4. **Update your requirements file**: 
   ```powershell
   pip freeze > requirements.txt
   ```

---

## 🎯 Task 2: Start the Jupyter Notebook Server
Once installed, Jupyter runs as a local "server" on your machine. 

### Step-by-step:
1. While still inside your activated virtual environment, run:
   ```powershell
   jupyter notebook
   ```
   **Expected Output:**
   ```text
   [I 2026-05-11 10:00:00.000 ServerApp] jupyter_server | extension was successfully linked.
   [I 2026-05-11 10:00:00.000 ServerApp] Serving notebooks from local directory: C:\Users\HP\Documents\Learning-Content\100-days-ML-challenge
   [I 2026-05-11 10:00:00.000 ServerApp] Jupyter Server 2.13.0 is running at:
   [I 2026-05-11 10:00:00.000 ServerApp] http://localhost:8888/tree?token=abcdef1234567890abcdef1234567890
   [I 2026-05-11 10:00:00.000 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
   ```
2. **What happens next?**
   * **Do not close this terminal!** If you close it, the Jupyter server stops running.
   * Your default web browser should automatically open a new tab pointing to the Jupyter interface.

---

## 🎯 Task 3: Create Your First Notebook

### Step-by-step:
1. In the Jupyter browser interface, look at the top right corner for a button labeled **"New"**.
2. Click **"New"** and select **"Python 3 (ipykernel)"** from the dropdown.
3. A new tab will open with a blank notebook.
4. Click inside the grey rectangular box (this is a "cell"). Type:
   ```python
   import numpy as np
   import pandas as pd
   
   print("Jupyter is working perfectly!")
   ```
5. Press **Shift + Enter** on your keyboard to run the cell.
   **Expected Output (in the browser):**
   ```text
   Jupyter is working perfectly!
   ```

---

## 🏁 Wrap Up
To gracefully shut down your Jupyter server when you are done working:
1. Go back to your PowerShell terminal where the server is running.
2. Press **Ctrl + C** twice to stop the server.
   **Expected Output:**
   ```text
   [C 2026-05-11 10:05:00.000 ServerApp] shutdown confirmed
   [I 2026-05-11 10:05:00.000 ServerApp] Shutting down 0 kernels
   [I 2026-05-11 10:05:00.000 ServerApp] Shutting down extension: jupyter_server
   ```
3. You can then `deactivate` your environment.
