Jupyter Notebook & Google Colab: AI Experiments નું Playground
Python Environment Setup થઈ ગઈ. Libraries Install થઈ. હવે Code ક્યાં લખવો?
Terminal માં? — ભૂલ આવે, Output ગાયબ, Graph ક્યાં Show?
Jupyter Notebook અને Google Colab — AI Developers ના સૌથી પ્રિય Tools — Code + Output + Notes + Graphs — બધું એક જ જગ્યાએ.
Jupyter Notebook એટલે શું?
Jupyter Notebook = Interactive Coding Environment — Code લખો, ઝટ Run કરો, Output ત્યાં જ નીચે દેખાય.
Normal Python File (.py):
- બધો Code લખો → Run → Output Terminal માં
Jupyter Notebook (.ipynb):
- Cell-by-Cell Code → Cell Run → Output ત્યાં જ → Next Cell
💡 Analogy: Normal .py File = Book (બધું એક સાથે). Jupyter = Interactive Workbook — Page-by-Page ભરો, જુઓ, સુધારો.
Jupyter Notebook Install અને Open
# Virtual Environment Activate કરો (Python Environment Post યાદ?)
source venv/bin/activate
# Jupyter Install
pip install jupyter notebook
# Jupyter Open
jupyter notebook
Browser Automatic ખૂલશે — http://localhost:8888
JupyterLab (Advanced Version):
pip install jupyterlab
jupyter lab
JupyterLab = Jupyter ની Modern, Cleaner Version — Side Panel, Multiple Tabs.
Notebook ની અંદર — 3 Cell Types
Jupyter Notebook 3 પ્રકારના Cells:
1. Code Cell — Python Code
x = 10
y = 20
print(x + y)
Output: 30 — Cell ની નીચે ઝટ
2. Markdown Cell — Notes / Headings
## મારો પ્રથમ AI Experiment
- Dataset: Iris Flowers
- Model: Decision Tree
Output: સુંદર Formatted Text — Documentation ભૂ
3. Raw Cell — Plain Text
Code ન ચાલે, Format ન થાય — ક્વચિત ઉપયોગ.
Important Keyboard Shortcuts
| Shortcut | કામ |
|---|---|
Shift + Enter |
Cell Run, Next Cell |
Ctrl + Enter |
Cell Run, Same Cell |
A |
ઉપર New Cell |
B |
નીચે New Cell |
DD |
Cell Delete |
M |
Markdown Cell |
Y |
Code Cell |
Ctrl + S |
Save |
⚡ Pro Tip:
Shift+Enterસસ`fast workflow — Run & Move.
Jupyter માં AI Workflow
# Cell 1: Libraries Import
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Cell 2: Data Load
df = pd.read_csv('data.csv')
df.head() # ઝટ First 5 Rows Show
# Cell 3: Data Shape
print(df.shape) # (Rows, Columns)
print(df.info()) # Data Types
# Cell 4: Graph
plt.plot(df['age'], df['salary'])
plt.title('Age vs Salary')
plt.show() # Graph ત્યાં જ Notebook માં!
# Cell 5: ML Model
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X_train, y_train)
print("Score:", model.score(X_test, y_test))
બધું Notebook ના એક File માં — Code, Output, Graph, Notes.
Google Colab — No Setup, Free GPU
Google Colab = Jupyter Notebook + Cloud + Free GPU — Browser માં ખૂલો, Code લખો, Run કરો — Laptop ઉપર કંઈ Install ન કરો!
🔗 Open: colab.research.google.com — Google Account ઘરે Ready.
Colab vs Local Jupyter
| Local Jupyter | Google Colab | |
|---|---|---|
| Setup | Install જોઈએ | ❌ Nothing — Browser ખૂલો |
| GPU | Laptop GPU (Limited) | ✅ Free NVIDIA GPU |
| Storage | Local Disk | Google Drive |
| Offline | ✅ | ❌ Internet જોઈએ |
| Cost | Free | Free (Limits સાથે) |
| Share | File Share | ✅ Link Share (Google Docs જેમ) |
| Beginners | Setup જોઈએ | ✅ ઝટ શરૂ |
Google Colab ઉપર First Notebook
Step 1: colab.research.google.com ખૂલો
Step 2: "New Notebook" Click
Step 3: Code Cell માં:
print("નમસ્તે, AI દુનિયા!")
Shift+Enter — Output ઝટ!
Step 4: GPU Enable:
Runtime → Change Runtime Type → GPU → Save
Step 5: Libraries (Colab ઉપર Pre-Installed)
import tensorflow as tf
import torch
import pandas as pd
import numpy as np
# — Install વગર Ready!
Colab ઉપર Google Drive Connect
from google.colab import drive
drive.mount('/content/drive')
# Drive ની File Read
df = pd.read_csv('/content/drive/MyDrive/data/myfile.csv')
💡 Drive Mount = Colab ને Google Drive નો Access — Files Upload/Download Easy.
Colab GPU Check
import torch
print(torch.cuda.is_available()) # True = GPU Ready
print(torch.cuda.get_device_name(0)) # GPU Name (e.g., Tesla T4)
import tensorflow as tf
print(tf.config.list_physical_devices('GPU'))
Colab Limits (Free Version)
| Limit | વિગત |
|---|---|
| Session Time | ~12 કલાક (Idle = Disconnect) |
| GPU | NVIDIA T4 (Free), A100 (Pro) |
| RAM | ~12 GB (Free) |
| Disk | ~107 GB Temporary |
| Idle Timeout | ~90 મિનિટ Inactive = Session End |
⚠️ Important: Colab Session End = Local Files Delete! Google Drive Mount કરો — Data Safe.
Jupyter vs Colab — ક્યારે શું?
| Situation | ઉપયોગ |
|---|---|
| Offline, Local Data | Local Jupyter |
| Quick Experiment, No Setup | Google Colab |
| Free GPU (Large Model Train) | Google Colab |
| Team ને Share | Google Colab |
| Production-ready Code | Local + .py Files |
| Sensitive Data (Privacy) | Local Jupyter |
Magic Commands — Jupyter/Colab Secret Powers
Magic Commands = Jupyter ના Special Commands — % અથવા %% થી શરૂ.
# Code ચાલવામાં Time
%time model.fit(X_train, y_train)
# બધી Variables List
%who
# Matplotlib Graphs Notebook ની અંદર
%matplotlib inline
# Shell Command Notebook ની અંદર
!pip install transformers
!ls data/
# External .py File Run
%run src/train.py
💡
!= Terminal Command Notebook ની અંદર —!pip install,!git clone— ઘણો ઉપયોગ Colab ઉ
AI Project Notebook Best Practices
✅ Cells Numbered Order માં — Cell 1: Import, Cell 2: Data, Cell 3: EDA, Cell 4: Model
✅ Markdown Cells — Section Headings, Notes — Future Self ને સમજાય
✅ "Restart & Run All" — Notebook Order Check — ઉપરથી નીચે ચાલે
✅ Output Clear — Git Commit પહેલા — File Size ઓછી
✅ Google Drive Mount — Colab ઉપર Data Safe
✅ .ipynb Git Ignore — Large Output Files — Optional
Colab Pro / Pro+ — ક્યારે?
| Free | Pro (~₹900/month) | Pro+ (~₹1800/month) | |
|---|---|---|---|
| GPU | T4 | A100 | A100 High RAM |
| RAM | 12 GB | 25 GB | 51 GB |
| Session | 12 hrs | 24 hrs | 24 hrs |
| Background | ❌ | ✅ | ✅ |
💡 Beginners / Students — Free Version Plenty! Large Model Fine-tuning ઉપર Pro ઉપયોગ.
નિષ્કર્ષ
| Jupyter Notebook | Google Colab | |
|---|---|---|
| Best For | Local, Offline, Privacy | Quick, GPU, Share |
| Setup | pip install | Zero |
| Beginner Friendly | ✅ | ✅✅ |
🧪 AI Developer ની Journey: Python Install → venv → Jupyter/Colab → Code → Experiment → Model → Deploy
Google Colab ઉપર આજે જ Notebook ખોલો — 5 Minutes, Zero Setup, AI Experiment Ready! 🚀