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


What You’ll Learn


📋 Lab Guide

Step 1: Install Python

  1. Download Python 3.10+ from python.org
  2. Run the installer
  3. Important: Check “Add Python to PATH”
  4. Verify: Open terminal and run python --version
  1. Download Anaconda from anaconda.com
  2. Run the installer
  3. Follow the installation wizard
  4. Verify: Run conda --version in 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


🔗 Resources


📥 Submission


Next: Practical 2 → Back to Practicals