Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Month 1 — Exercises collection

This page contains additional exercises on all topics. In addition to the exercises at the end of each chapter, complete these too — for deeper understanding.

🟢 Easy-level exercises

Math

  1. Create a (5, 5) random matrix with NumPy, compute its rank.
  2. Compute variance and standard deviation of vector [2, 4, 6, 8, 10] by hand and with NumPy.
  3. Explain whether the following statements are true or false:
  • “Mean is always the best measure of central tendency”
  • “Standard deviation is the square root of variance”

NumPy

  1. Using np.eye(5), create a 5x5 identity matrix.
  2. Reshape [1, 2, 3, 4, 5, 6, 7, 8, 9] to a (3, 3) matrix and take its transpose.
  3. Compute Euclidean distance between two random (100,) vectors.

Pandas

  1. Read a CSV file and output the first 5 rows in JSON format.
  2. Replace spaces in column names with _ (df.columns.str.replace).
  3. Find both empty and 0 values in a DataFrame, output their count.

Visualization

  1. Plot sine and cosine functions on one chart.
  2. Plot bar plot in 4 different colors.
  3. For a random (50, 50) matrix, plot heatmap using imshow.

🟡 Medium-level exercises

Working with real datasets

  1. Iris dataset: load via seaborn.load_dataset('iris'). Plot distribution of each feature by species using violin plot.
  2. Tips dataset: load seaborn.load_dataset('tips'). Output average tip by day and time as a pivot table.
  3. Custom dataset: export real data from your Django/FastAPI project (orders, users, events) and start EDA.

Vectorization exercises

  1. Implement function sigmoid(x) = 1 / (1 + exp(-x)) in NumPy. Compare with pure Python loop for 1M elements.
  2. Implement softmax(x) = exp(x) / sum(exp(x)) — with numerical stability (x - max(x)).
  3. Implement moving average — (window=10), no loops in NumPy.

Pandas pipelines

  1. E-commerce funnel: compute user transition rates view → cart → purchase.
  2. Cohort retention: divide users into cohorts by registration month, plot 6-month retention.
  3. RFM Analysis: compute Recency, Frequency, Monetary metrics for each customer and split into segments.

🔴 Hard-level exercises (Backend integration)

1. Analytics API (FastAPI)

Create a complete FastAPI service with the following endpoints:

POST /api/v1/analytics/upload      # CSV/JSON dataset yuklash
GET  /api/v1/analytics/{id}/summary # describe() natijasi
GET  /api/v1/analytics/{id}/chart   # PNG chart qaytarish
GET  /api/v1/analytics/{id}/report  # ydata-profiling HTML
POST /api/v1/analytics/{id}/query   # custom SQL-like so'rov

Requirements:

  • Store loaded datasets in Redis or on disk (with TTL)
  • Fully type-safe with Pydantic models
  • Automatic OpenAPI docs
  • Unit tests with Pytest

2. Django Admin Reports

Add a admin custom action to your existing Django project (or create a new one):

  • PDF report generation for selected objects
  • Charts using Pandas + matplotlib
  • PDF via ReportLab or WeasyPrint

3. Real-time Dashboard

Create a real-time dashboard with Server-Sent Events (SSE):

  • FastAPI backend serves fresh data every 5 seconds
  • Frontend (simple HTML+Chart.js)
  • Pandas aggregates on the backend side
  • Plotly sends data in JSON format

4. Data Quality Service

Using Pandera or Great Expectations:

  • Schema validation for uploaded CSV
  • Quality score (0-100)
  • Detect anomalies (outliers, type mismatch)
  • Slack notification on incorrect data

Mini-projects (each 1-2 weeks)

Mini-project 1: Personal Finance Tracker

  • Your own bank statement (CSV)
  • Categorization via Pandas (rules-based)
  • Monthly expenses dashboard
  • Trends and anomalies
  • Interactive UI in Streamlit

Mini-project 2: GitHub Profile Analyzer

  • Load your repos from GitHub API
  • Code distribution by language
  • Commit activity (calendar heatmap)
  • Top contributors
  • Automatically embed in README

Mini-project 3: Uzbekistan Open Data EDA

  • Take dataset from data.gov.uz and do EDA
  • Write insights in Uzbek
  • Publish as a post on Habr.com/dev.to

Quiz (self-test)

Pandas

  1. What’s the difference between df.iloc[0] and df.loc[0]?
  2. Difference between df.merge() with how='left' and how='outer'?
  3. When are apply() and map() used?
  4. Difference between transform() and agg()?
  5. How to optimize a large DataFrame in memory? (category dtype, downcast)

NumPy

  1. Difference between np.array and np.asarray?
  2. Explain the broadcasting rule.
  3. What’s the difference between np.copy() and [:] slicing?
  4. Relation of axis=0 and axis=1 to (rows, cols)?
  5. Does np.vectorize() really make things faster? (Hint: no!)

Math

  1. Formula of cosine similarity and why is it used?
  2. What happens if the learning rate in gradient descent is too large?
  3. Difference between normal distribution and uniform distribution?
  4. Explain Bayes theorem in your own words.
  5. correlation = 0 — does this always mean “no relationship”? (Hint: no, only no linear relationship)

✅ End-of-month checklist

  • Math chapter completed, gradient descent code written
  • NumPy exercises completed, I understand broadcasting
  • Pandas EDA exercises (Titanic / House Prices)
  • Visualization exercises, FastAPI endpoint returning PNG
  • Capstone: one complete EDA project on GitHub
  • LinkedIn post (with link to project)

Congratulations! Ready for Month 2 — Classical ML.