MACHINE LEARNING

106403
Back to MACHINE LEARNING

Module 2: Linear Models and Bayesian Learning

  1. Q1c. What makes the difference between good decisions and bad decisions? (i) A good decision is based on logic (ii) A good decision considers all available data (iii) A good decision considers all alternatives (iv) A good decision applies quantitative approaches20222m

    Module 2: Linear Models and Bayesian Learning

    What makes the difference between good decisions and bad decisions?
    (i) A good decision is based on logic
    (ii) A good decision considers all available data
    (iii) A good decision considers all alternatives
    (iv) A good decision applies quantitative approaches

    View this question on its own page →
    Worked Solution

    Answer: (iv) A good decision applies quantitative approaches — though in ML/decision theory all (i)-(iii) also contribute, expected exam answer is (iv).

    Explanation:

    In Statistical Decision Theory / ML:

    • Good decisions are not just based on logic (i) alone — logic without data is insufficient.
    • Considering all data (ii) and all alternatives (iii) are part of rational decision making, but alone not distinctive.
    • Quantitative approaches (iv) — using probability, expected loss/risk R(a)=∫L(a,y)p(y∣x)dyR(a) = \int L(a,y) p(y|x) dy, utility, optimization — differentiate good from bad decisions objectively. This aligns with Bayesian decision theory, where you choose action a∗=arg⁡min⁡aE[L]a^* = \arg\min_a E[L].

    Textbook often phrases: "A good decision is based on logic, considers all available data and alternatives, and applies quantitative approaches." If single best is asked, (iv) captures the statistical/ML perspective (quantitative risk minimization) that the other options miss. If multiple correct, (ii)+(iii)+(iv) would be joint.

  2. Q1d. Where does the Bayes rule can be used? (i) Solving queries (ii) Increasing complexity (iii) Decreasing complexity (iv) Answering probabilistic query20222m

    Module 2: Linear Models and Bayesian Learning

    Where does the Bayes rule can be used?
    (i) Solving queries
    (ii) Increasing complexity
    (iii) Decreasing complexity
    (iv) Answering probabilistic query

    View this question on its own page →
    Worked Solution

    Answer: (iv) Answering probabilistic query — (i) Solving queries is also acceptable but (iv) is more precise.

    Explanation:

    Bayes Rule: P(H∣E)=P(E∣H)P(H)P(E)P(H|E) = \frac{P(E|H)P(H)}{P(E)}

    Uses:

    • Answering probabilistic queries — compute posterior P(query∣evidence)P(query | evidence), e.g., P(disease∣symptoms)P(disease|symptoms).
    • Solving queries in Bayesian networks: Inference via enumeration, variable elimination, MCMC.
    • Classification (Naive Bayes): P(y∣x)∝P(x∣y)P(y)P(y|x) \propto P(x|y)P(y)
    • Updating beliefs with evidence, spam filtering, medical diagnosis.

    It does NOT increase/decrease complexity inherently; it enables probabilistic reasoning.

    Hence (iv) Answering probabilistic query is textbook best. (i) Solving queries is vague but related — if single choice forced, pick (iv).

  3. Q1e. Which of the following steps/assumptions in regression modeling impacts the trade-off between under-fitting and over-fitting the most? (i) The polynomial degree (ii) Whether we learn the weights by matrix inversion or gradient descent (iii) The use of a constant-term (iv) None of the above20222m

    Module 2: Linear Models and Bayesian Learning

    Which of the following steps/assumptions in regression modeling impacts the trade-off between under-fitting and over-fitting the most?
    (i) The polynomial degree
    (ii) Whether we learn the weights by matrix inversion or gradient descent
    (iii) The use of a constant-term
    (iv) None of the above

    View this question on its own page →
    Worked Solution

    Answer: (i) The polynomial degree

    Explanation — Underfitting vs Overfitting trade-off:

    • Model complexity controls bias-variance trade-off. Polynomial degree directly controls capacity:

      • Degree=1 (linear) — high bias, may underfit non-linear data
      • Degree too high (e.g., 10 for 20 points) — low bias but high variance, overfits noise, oscillates
    • (ii) Whether we learn weights by matrix inversion vs gradient descent — Both solve same optimization w=(XTX)−1XTyw = (X^T X)^{-1}X^T y vs iterative; they reach same ww (if convex), so no impact on generalization.

    • (iii) Use of constant-term (bias w0w_0) — Important to fit intercept, but small impact compared to degree. Without bias, model forced through origin — may underfit slightly, but not as dramatic as degree change.

    Thus degree (i) is the dominant hyperparameter governing over/under-fitting.

    Other factors affecting trade-off: regularization λ\lambda, training set size, early stopping.

  4. Q3a. What is Linear Regression? Explain in detail using example and list all the assumption to be met before starting with linear regression.20237m

    Module 2: Linear Models and Bayesian Learning

    What is Linear Regression? Explain in detail using example and list all the assumption to be met before starting with linear regression.

    View this question on its own page →
    Worked Solution

    Linear Regression:

    Model: y=w0+w1x1+...+wdxd+ϵ=wTx+b+ϵy = w_0 + w_1 x_1 + ... + w_d x_d + \epsilon = w^T x + b + \epsilon, with ϵ∼N(0,σ2)\epsilon\sim N(0,\sigma^2). Goal: learn ww minimizing squared loss J(w)=∑(yi−wTxi)2J(w)=\sum (y_i - w^T x_i)^2 or MLE under Gaussian noise.

    Closed form: w∗=(XTX)−1XTyw^* = (X^T X)^{-1}X^T y (OLS). Gradient descent also: $w:=w-\eta
    abla J$.

    Example: Predict house price yy (in lakhs) from size xx (sq ft). Data: (1000,50), (1500,70), (2000,90) → learn y≈0.04x+10y\approx 0.04x +10 → for 1200 sq ft predict 5858L.

    Types: Simple (one predictor), Multiple (many), Polynomial (features x2,x3x^2, x^3 but linear in parameters).

    Assumptions to be met before Linear Regression:

    1. Linearity: Relationship between XX and YY is linear (check scatter plot, residuals vs fitted).
    2. Independence of errors: Observations independent (no autocorrelation, Durbin-Watson).
    3. Homoscedasticity: Constant variance of residuals Var(ϵ∣X)=σ2Var(\epsilon|X)=\sigma^2 (Breusch-Pagan test).
    4. Normality of residuals: ϵ∼Normal\epsilon \sim Normal for inference (Q-Q plot, Shapiro-Wilk) — not strictly for prediction.
    5. No multicollinearity: Predictors not highly correlated (VIF <5-10).
    6. No autocorrelation and no endogeneity (E[ϵ∣X]=0E[\epsilon|X]=0).
    7. No influential outliers (Cook's distance).
    8. Features not random, measured without error, sample size n≫dn \gg d.

    Checks/Remedies: Transform variables (log), remove outliers, ridge if multicollinearity, Weighted LS if heteroscedasticity. Violations bias estimates / invalidate p-values.

  5. Q3b. What is regression analysis? What are the differences between linear regression and ridge regression?20227m

    Module 2: Linear Models and Bayesian Learning

    What is regression analysis? What are the differences between linear regression and ridge regression?

    View this question on its own page →
    Worked Solution

    Regression Analysis: Statistical process for estimating relationships among variables. Predict continuous dependent yy from independent XX. Model y=f(X;θ)+ϵy = f(X;\theta)+\epsilon. Used for prediction, inference of variable importance, trend estimation.

    Types: Simple linear, multiple linear, polynomial, ridge/lasso, logistic (classification), non-linear.

    Linear Regression:

    • Model: y=Xβ+ϵy = X\beta + \epsilon, ϵ∼N(0,σ2)\epsilon\sim N(0,\sigma^2)
    • Assumes linear relationship, homoscedasticity.
    • OLS solution: β^=(XTX)−1XTy\hat\beta = (X^T X)^{-1}X^T y
    • Loss: RSS=∑(yi−y^i)2RSS = \sum(y_i- \hat y_i)^2
    • Suffers when XTXX^T X singular/multicollinear, overfits with many features, sensitivity to outliers.

    Ridge Regression (L2 Regularized):

    • Loss: J(β)=RSS+λ∣∣β∣∣22=∑(yi−xiTβ)2+λ∑βj2J(\beta)= RSS + \lambda||\beta||_2^2 = \sum(y_i- x_i^T\beta)^2 + \lambda\sum\beta_j^2, λ≥0\lambda\ge0
    • Solution: β^ridge=(XTX+λI)−1XTy\hat\beta_{ridge}=(X^T X + \lambda I)^{-1}X^T y
    • Adds bias but reduces variance (bias-variance trade-off), handles multicollinearity by shrinking coefficients, XTX+λIX^T X + \lambda I always invertible.
    • Does feature shrinkage, not selection (all βj\beta_j non-zero). Lasso (L1L1) does selection.
    Aspect Linear Ridge
    Penalty none λ∣∣β∣∣2\lambda||\beta||^2
    Coefficients unbiased, high variance if collinear biased (shrink toward 0), lower variance
    When p>np>n fails works
    Hyperparameter none λ\lambda via CV
    Interpretability direct shrunk values

    Ridge is preferred when multicollinearity, high dimensional or overfitting risk.

  6. Q5b. A patient takes a lab test and the result comes back positive. It is known that the test returns a correct positive result in only 98% of the cases and a correct negative result in only 97% of the cases. Furthermore, only 0.008 of the entire population has this disease. (i) What is the probability that this patient has cancer? (ii) What is the probability that he does not have cancer? (iii) What is the diagnosis?20237m

    Module 2: Linear Models and Bayesian Learning

    A patient takes a lab test and the result comes back positive. It is known that the test returns a correct positive result in only 98% of the cases and a correct negative result in only 97% of the cases. Furthermore, only 0.008 of the entire population has this disease.
    (i) What is the probability that this patient has cancer?
    (ii) What is the probability that he does not have cancer?
    (iii) What is the diagnosis?

    View this question on its own page →
    Worked Solution

    Given: Test correct positive P(+∣D)=0.98P(+|D)=0.98 (sensitivity), correct negative $P(-|
    eg D)=0.97(specificity)→falsepositive (specificity) → false positive P(+|
    eg D)=0.03,diseaseprevalence, disease prevalence P(D)=0.008$.

    We compute posterior using Bayes: P(D∣+)=P(+∣D)P(D)P(+)P(D|+) = \frac{P(+|D)P(D)}{P(+)} where $P(+)=P(+|D)P(D)+P(+|
    eg D)P(
    eg D)$.

    • P(D)=0.008P(D)=0.008, $P(
      eg D)=0.992$
    • P(+∣D)=0.98P(+|D)=0.98, $P(+|
      eg D)=1-0.97=0.03$

    P(+)=0.98∗0.008+0.03∗0.992=0.00784+0.02976=0.0376P(+) =0.98*0.008 +0.03*0.992 =0.00784+0.02976=0.0376

    (i) P(D∣+)=0.00784/0.0376≈0.2085≈20.9%P(D|+) =0.00784/0.0376 \approx 0.2085 \approx 20.9\%

    **(ii) $P(
    eg D|+) =1 -0.2085=0.7915 \approx 79.2%∗∗(or** (or 0.02976/0.0376=0.7915$)

    (iii) Diagnosis: Despite positive test, patient most probably does NOT have cancer/disease (about 79% chance healthy) because disease is rare (base rate fallacy). Positive predictive value only ~21%. Recommend further testing (more specific test, follow-up) — do not immediately diagnose cancer. If used as MAP classifier, predict $
    eg D$
    (no cancer).

    Note: This classic low-prevalence paradox shows importance of prior. If prevalence higher, posterior rises sharply.

  7. Q9a. Write short notes on the following: (a) Partial least square20227m

    Module 2: Linear Models and Bayesian Learning

    Write short notes on the following:
    (a) Partial least square

    View this question on its own page →
    Worked Solution

    (a) Partial Least Squares (PLS):

    PLS is dimensionality reduction + regression method for high-dimensional, multicollinear, p≫np\gg n data (e.g., chemometrics, genomics).

    Goal: Find latent components that maximize covariance between XX (predictors) and YY (responses), not just variance of XX like PCA.

    Idea: Decompose X=TPT+EX = TP^T + E, Y=UQT+FY = UQ^T + F with T=XWT = XW, U=YCU = YC latent scores, weights WW maximize Cov(T,U)=Corr(T,U)∗Var(T)Var(U) Cov(T,U) = Corr(T,U) * \sqrt{Var(T)Var(U)}.

    Algorithm (NIPALS):

    1. Center/scale X,YX, Y.
    2. For component h=1..Ah=1..A: compute weight wh∝XTyw_h \propto X^T y (for univariate YY) normalized, th=Xwht_h = X w_h, ph=XTth/(thTth)p_h = X^T t_h / (t_h^T t_h), qh=YTth/(thTth)q_h = Y^T t_h / (t_h^T t_h), deflate X:=X−thphTX:= X - t_h p_h^T, Y:=Y−thqhTY:= Y - t_h q_h^T.
    3. Regression Y=TBQTY = T B Q^T yields β^PLS=W(PTW)−1BQT\hat\beta_{PLS}= W(P^T W)^{-1} B Q^T.

    Types: PLS1 (YY univariate), PLS2 (YY multivariate), PLS-DA (classification).

    Advantages: Handles multicollinearity, n<pn<p, noisy predictors, stable; gives interpretable latent factors (like PCA but supervised).

    Vs PCA/OLS: PCA maximizes Var(T)Var(T), PLS maximizes Cov(T,U)Cov(T,U) → better predictive components. OLS fails when XTXX^T X singular; PLS works.

    Choosing components AA: Cross-validation (Q² metric).

    Example: Predict chemical concentration YY from 1000-wavelength spectra XX (highly correlated) with 50 samples → PLS finds 3 latent factors capturing predictive spectra shape.