IIT Madras Zanzibar · Teaching

← Z3003 Data Mining

Lab Explorer & Part 2 Code Previews

Interactive reference guide to Z3003 executable Python modules, complexity bounds, verified self-test outputs, and one-click Google Colab notebooks spanning Part 1 foundations and Part 2 large-scale algorithms.

Part 2 · Weeks 10–11SGD per epoch: O(|K| * k) time · O((|U| + |I|) * k) memory

DM07: Recommender Systems & Matrix Factorization (SVD)

Implements user-based cosine collaborative filtering and biased latent-factor SGD matrix factorization with L2 regularization and RMSE evaluation.

Python Preview
def matrix_factorization_sgd(ratings, n_users, n_items, k=4, lr=0.03, reg=0.02, epochs=120):
    mu = float(np.mean([r for _, _, r in ratings]))
    bu, bi = np.zeros(n_users), np.zeros(n_items)
    P = rng.normal(0.0, 0.1, size=(n_users, k))
    Q = rng.normal(0.0, 0.1, size=(n_items, k))
    for _ in range(epochs):
        for u, i, r in ratings:
            err = r - (mu + bu[u] + bi[i] + float(Q[i] @ P[u]))
            bu[u] += lr * (err - reg * bu[u])
            bi[i] += lr * (err - reg * bi[i])
            P[u], Q[i] = P[u] + lr * (err * Q[i] - reg * P[u]), Q[i] + lr * (err * P[u] - reg * Q[i])
    return mu, bu, bi, P, Q
DM07 self-tests passed (Train RMSE=0.0685; User-CF & Biased SVD verified).
Part 2 · Weeks 12–13Power iteration: O((V + E) * iters) time · O(V + E) memory

DM08: Web Graph, PageRank Power Iteration & HITS

Builds column-stochastic transition matrices with dead-end mass redistribution, random teleportation (beta = 0.85), and normalized HITS hub/authority updates.

Python Preview
def pagerank(adj, beta=0.85, tol=1e-10, max_iter=200):
    # Dead ends redistribute uniform mass 1/n across all nodes to prevent rank leak
    r = np.full(n, 1.0 / n, dtype=float)
    teleport = (1.0 - beta) / n
    for iters in range(1, max_iter + 1):
        r_next = beta * (M @ r) + teleport
        if float(np.sum(np.abs(r_next - r))) < tol:
            return {u: float(r_next[idx[u]]) for u in nodes}, iters
        r = r_next
DM08 self-tests passed (PageRank converged cleanly with dead-end handling & HITS verified).
Part 2 · Weeks 14–15Single pass: O(1) per stream item · O(k * log U) sketch memory

DM09: Data Streams (Flajolet-Martin & AMS Second Moment)

Estimates distinct element cardinality F0 via trailing-zero bit sketches across independent hashes and tracks frequency second moment F2 using unbiased AMS estimators.

Python Preview
def flajolet_martin_estimate(stream, n_hashes=16, groups=4):
    # Track max trailing zero bit position R per hash; take median of group means
    max_r = [0] * n_hashes
    for item in stream:
        for h_idx in range(n_hashes):
            max_r[h_idx] = max(max_r[h_idx], _trailing_zeros(hash_val(item, h_idx)))
    return float(statistics.median(group_means))
DM09 self-tests passed (Flajolet-Martin F0 & AMS F2 stream sketches verified).
Part 1 & Project · Weeks 1–6Leakage-free pipelines · MinHash LSH · Bloom O(m) bits · RF/KMeans

Part 1 Core Modules (DM01–DM06) & Mini-Project Starter (MP01)

Complete verified Python modules covering Bayesian MLE, Information Gain / PCA / LDA, SMOTE & Ensembles, MapReduce / PySpark RDDs (plus Lab 1 HTML walkthrough), MinHash LSH, Apriori & Bloom Filters, and the end-to-end Zanzibar crop Mini-Project starter.

Python Preview
# Verified end-to-end Mini-Project Starter outputs on W1_zanzibar_crop_sample.csv (500 rows):
# - Confounder check: price_per_kg vs. revenue_usd r = 0.922 (driven by crop type)
# - Leakage-free RandomForest held-out accuracy >= 0.92, KMeans best_k = 2
All DM01-DM09 and MP01 self-tests passed in automated unittest harness.

Complete Part 1 Module Quick-Launch (DM01–DM06)

ModuleTopicsFiles & Colab
DM01Bayesian Decision Theory, Bernoulli & Gaussian MLE.py .ipynb Colab ↗
DM02Information Gain Feature Selection, PCA & Fisher LDA.py .ipynb Colab ↗
DM03Class Imbalance, SMOTE & Ensembles (RF, AdaBoost, GBDT).py .ipynb Colab ↗
DM04MapReduce & PySpark RDD Log / OLAP Pipelines (HTML Lab 1).py .ipynb Colab ↗
DM05k-Shingling, Jaccard, MinHash Signatures & LSH Banding.py .ipynb Colab ↗
DM06Apriori Frequent Patterns, Kulczynski/IR & Bloom Filters.py .ipynb Colab ↗