Practical 1: Python Foundations & Environment Setup
Objective
Set up a complete machine learning environment and verify that all necessary tools are installed and working correctly.
Duration
2-3 hours (including downloads and installation)
Prerequisites
- Computer with Windows, macOS, or Linux
- Internet connection
- Administrator access (for software installation)
What You’ll Learn
- ✅ Install Python and Anaconda
- ✅ Set up virtual environments
- ✅ Install essential ML libraries (NumPy, Pandas, Scikit-learn)
- ✅ Configure Jupyter Notebook
- ✅ Verify installation with test programs
📋 Lab Guide
Step 1: Install Python
- Download Python 3.10+ from python.org
- Run the installer
- Important: Check “Add Python to PATH”
- Verify: Open terminal and run
python --version
Step 2: Install Anaconda (Recommended)
- Download Anaconda from anaconda.com
- Run the installer
- Follow the installation wizard
- Verify: Run
conda --versionin terminal
Step 3: Create Virtual Environment
conda create -n ml_env python=3.10
conda activate ml_env
Step 4: Install Essential Libraries
conda install numpy pandas scikit-learn matplotlib seaborn jupyter
# OR using pip:
pip install numpy pandas scikit-learn matplotlib seaborn jupyter
Step 5: Test Installation
python test_installation.py
💻 Sample Code
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# NumPy test
arr = np.array([1, 2, 3, 4, 5])
print(f"NumPy array: {arr}")
print(f"Mean: {arr.mean()}")
# Pandas test
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
print("\nPandas DataFrame:")
print(df)
# Matplotlib test
plt.plot([1, 2, 3, 4], [1, 4, 2, 3])
plt.title("Test Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.savefig("test_plot.png")
print("\nPlot saved as test_plot.png")
📝 Jupyter Notebook
Launch Jupyter Notebook:
jupyter notebook
Then access it at http://localhost:8888
📊 Learning Outcomes
- Python installed and working
- Virtual environment created
- All libraries imported successfully
- First NumPy, Pandas, and Matplotlib operations completed
- Jupyter Notebook launched and working
🔗 Resources
📥 Submission
- Screenshot of
python --versionoutput - Output of test_installation.py
- First Jupyter notebook with above code
| Next: Practical 2 → | Back to Practicals |