MACHINE LEARNING
106403Unit 3: Classification & Regression
Q1e. Logistic regression uses which loss function? (i) Mean Squared Error (ii) Euclidean Distance (iii) Cross-Entropy (iv) Hinge Loss20252m
Unit 3: Classification & Regression
View this question on its own page →Logistic regression uses which loss function?
(i) Mean Squared Error
(ii) Euclidean Distance
(iii) Cross-Entropy
(iv) Hinge LossWorked SolutionAnswer: (iii) Cross-Entropy (Log Loss / Binary Cross-Entropy)
Explanation:
Logistic regression models where and maximizes likelihood, equivalent to minimizing:
— Cross-Entropy / Log Loss
- MSE (i) is for linear regression; using it with sigmoid makes optimization non-convex and slow.
- Euclidean Distance (ii) not a classification loss.
- Hinge Loss (iv) is for SVM: .
Thus (iii) Cross-Entropy is correct. It heavily penalizes confident wrong predictions and yields convex optimization.
Q1f. A perceptron has weights w=[0.5, -0.5] and bias b=0. For input x=[1,1] with label y=1, the weight update with learning rate η=0.1 is (i) w=[0.6, -0.4], b=0.1 (ii) w=[0.4, -0.6], b=-0.1 (iii) w=[0.5, -0.5], b=0 (iv) w=[0.7, -0.3], b=0.220252m
Unit 3: Classification & Regression
View this question on its own page →A perceptron has weights w=[0.5, -0.5] and bias b=0. For input x=[1,1] with label y=1, the weight update with learning rate η=0.1 is
(i) w=[0.6, -0.4], b=0.1
(ii) w=[0.4, -0.6], b=-0.1
(iii) w=[0.5, -0.5], b=0
(iv) w=[0.7, -0.3], b=0.2Worked SolutionAnswer: (i) w=[0.6, -0.4], b=0.1
Solution:
Perceptron update rule: ,
Given
- Compute activation:
- Prediction: if else (or ). Here → (misclassified, since true ). Some texts use with as negative, same result.
- Error
- ,
If model predicted correctly (), no update → (iii). But with threshold at , is treated as incorrect, so update occurs → (i) is expected exam answer.
Note: If using with and counted as error, same. If using for , answer would be (iii) no update. Most exam keys expect (i).
Q1g. The kernel trick in SVM is used to (i) Map data to higher-dimensional space for linear separation (ii) Compute probabilities (iii) Reduce feature dimensions (iv) Normalize input features20252m
Unit 3: Classification & Regression
View this question on its own page →The kernel trick in SVM is used to
(i) Map data to higher-dimensional space for linear separation
(ii) Compute probabilities
(iii) Reduce feature dimensions
(iv) Normalize input featuresWorked SolutionAnswer: (i) Map data to higher-dimensional space for linear separation
Explanation:
SVM finds optimal linear hyperplane maximizing margin. Data not linearly separable in original space can be made separable by mapping to higher dimension where linear separation is possible (Cover's theorem).
Kernel trick: Avoids explicit computation; computes inner products in via kernel . Examples: Polynomial , RBF .
(ii) Compute probabilities — not kernel purpose (Platt scaling does, but not trick)
(iii) Reduce dimensions — opposite; it increases dimension implicitly (PCA reduces, kernel doesn't)
(iv) Normalize features — preprocessing, unrelated.
Thus (i) correct.
Q1h. Naive Bayes assumes (i) Features are dependent (ii) Features are independent given the class (iii) Class probabilities are equal (iv) No prior knowledge is required20252m
Unit 3: Classification & Regression
View this question on its own page →Naive Bayes assumes
(i) Features are dependent
(ii) Features are independent given the class
(iii) Class probabilities are equal
(iv) No prior knowledge is requiredWorked SolutionAnswer: (ii) Features are independent given the class
Explanation:
Naive Bayes uses:
Naive assumption: , i.e., features conditionally independent given class label. This drastically reduces parameters from to .
- (i) dependent — opposite of assumption
- (iii) class probabilities equal () — not assumed; priors estimated from data
- (iv) no prior — false; needs (estimated or uniform)
Therefore (ii) is correct. The independence is "naive" because in reality features often correlate, but model still works well in practice.
Q4a. Explain the concept of linear classifiers. How do they separate classes in feature space? Give examples of linearly separable and non-separable datasets.20257m
Unit 3: Classification & Regression
View this question on its own page →Explain the concept of linear classifiers. How do they separate classes in feature space? Give examples of linearly separable and non-separable datasets.
Worked SolutionLinear Classifiers:
Classifier where decision boundary is linear function . Prediction: (binary), or for multi-class. Hypothesis space: half-spaces.
How they separate in feature space:
- In , hyperplane splits space into two half-spaces. Distance from point to hyperplane .
- Learning finds minimizing loss (perceptron, logistic, SVM hinge). Geometrically, orientation and offset adjusted to separate classes.
- For , boundary is line; plane; higher hyperplane.
- Margin intuition (SVM): maximize distance between boundary and nearest points.
Linearly Separable example:
AND gate data: can be separated by . Points on opposite sides perfectly separable. Iris dataset (setosa vs versicolor with sepal length/width) approx linear.Non-separable example:
XOR: — no single line separates. Need non-linear boundary. Concentric circles, interleaving moons. Solution: map to higher dim via features or use kernel/nonlinear model (MLP with hidden layer).Limitation: Linear classifiers cannot capture XOR, curved boundaries without feature engineering/kernel trick. Advantage: simple, fast, interpretable, works when data approx linear or high-dim sparse (text).
Q4b. Explain the Perceptron learning algorithm. How does it update weights? Discuss its convergence properties.20257m
Unit 3: Classification & Regression
View this question on its own page →Explain the Perceptron learning algorithm. How does it update weights? Discuss its convergence properties.
Worked SolutionPerceptron Learning Algorithm (Rosenblatt 1957):
Linear binary classifier , (or ).
Algorithm:
Initialize
Repeat until convergence:
For each in training (random order):
Compute
Predict
If (misclassified):
else no update
learning rate (often 1).Weight Update Intuition: Move weight vector toward misclassified positive example () and away from negative, increasing score for correct class.
With labels: ,
Convergence Properties:
- Perceptron Convergence Theorem: If data is linearly separable with margin and radius , perceptron makes at most mistakes and converges to a separating hyperplane in finite steps, regardless of initialization or order. Does not guarantee maximum margin (unlike SVM).
- If data not separable, algorithm never converges, cycles — use Pocket algorithm (keep best weights) or averaging.
- Not sensitive to when separable (scaling).
- Online algorithm, mistake-driven, per epoch, fast.
Limitations: Cannot solve XOR, needs separable data; output is hard threshold, no probabilities. Extensions: kernel perceptron, voted perceptron, averaged perceptron for stability.
Example: AND gate converges in few steps; XOR never converges without hidden layer.Q5a. Explain the concept of SVM for linear classification. Define margin, support vectors, and how the optimal hyperplane is determined.20257m
Unit 3: Classification & Regression
View this question on its own page →Explain the concept of SVM for linear classification. Define margin, support vectors, and how the optimal hyperplane is determined.
Worked SolutionSVM for Linear Classification:
Goal: Find hyperplane that maximally separates classes .
Margin: Distance from hyperplane to closest training point. For canonical hyperplane , geometric margin , total margin width . SVM maximizes this.
Support Vectors: Training points lying exactly on margin boundaries . They are critical — removing non-support vectors doesn't change solution. Solution depends only on SVs where .
Optimal Hyperplane Determination:
Primal (hard margin):
s.t.For non-separable, soft margin with slack :
s.t. ,trades margin vs errors.
Solving:
Lagrangian dual: s.t. , . Quadratic programming. Then , from SV (average). Decision: .Geometric intuition: Push two parallel supporting hyperplanes as far apart as possible without violating, supports touch boundaries. Largest margin gives best generalization (VC dimension). Kernel trick extends to non-linear by .
Q5b. Explain the backpropagation algorithm. How are weights updated in a neural network using gradient descent?20257m
Unit 3: Classification & Regression
View this question on its own page →Explain the backpropagation algorithm. How are weights updated in a neural network using gradient descent?
Worked SolutionBackpropagation Algorithm — Weight Update via Gradient Descent:
For MLP with layers, loss or cross-entropy.
Steps:
Forward: , where is sigmoid/ReLU. Propagate to output.
Backward (output layer ): Error term (for MSE) or generally $ \delta^{(L)} =
abla E \odot f'(net)$.Hidden layers: — error weighted by downstream weights.
Gradients: ,
Update (SGD): ,
For batch: average over examples, momentum $\Delta w(t)= -\eta
abla E + \alpha\Delta w(t-1)\eta$.Role of Gradient Descent: Iteratively moves weights opposite gradient $w:=w-\eta
abla E\etaO(W)$ via chain rule, enabling deep learning.Variants: Vanilla SGD (per sample), mini-batch SGD, batch GD. Improvements: momentum, RMSProp, Adam, weight decay (L2).
Q8(b). Apply the ID3 algorithm on the following data to draw a decision tree. Show the Information Gain at each split. ### Dataset | Outlook | Temperature | Humidity | Windy | PlayTennis | |-----------|-------------|----------|-------|-------------| | Sunny | Hot | High | False | No | | Sunny | Hot | High | True | No | | Overcast | Hot | High | False | Yes | | Rainy | Mild | High | False | Yes | | Rainy | Cool | Normal | False | Yes | | Rainy | Cool | Normal | True | No | | Overcast | Cool | Normal | True | Yes | | Sunny | Mild | High | False | No | | Sunny | Cool | Normal | False | Yes | | Rainy | Mild | Normal | False | Yes | | Sunny | Mild | Normal | True | Yes | | Overcast | Mild | High | True | Yes | | Overcast | Hot | Normal | False | Yes | | Rainy | Mild | High | True | No |202510m
Unit 3: Classification & Regression
View this question on its own page →Apply the ID3 algorithm on the following data to draw a decision tree. Show the Information Gain at each split.
Dataset
Outlook Temperature Humidity Windy PlayTennis Sunny Hot High False No Sunny Hot High True No Overcast Hot High False Yes Rainy Mild High False Yes Rainy Cool Normal False Yes Rainy Cool Normal True No Overcast Cool Normal True Yes Sunny Mild High False No Sunny Cool Normal False Yes Rainy Mild Normal False Yes Sunny Mild Normal True Yes Overcast Mild High True Yes Overcast Hot Normal False Yes Rainy Mild High True No Worked SolutionID3 on PlayTennis (14 examples: 9 Yes, 5 No, )
Calculate
Outlook: Sunny (5:2Y3N, ), Overcast (4:4Y0N ), Rainy (5:3Y2N ) → Weighted → Gain=0.246
Temperature: Hot 4:2Y2N , Mild 6:4Y2N , Cool 4:3Y1N → Weighted → Gain
Humidity: High 7:3Y4N , Normal 7:6Y1N → Weighted → Gain
Windy: False 8:6Y2N , True 6:3Y3N → Weighted → Gain
Root = Outlook (max gain).
Outlook=Overcast → Leaf Yes (4/4 pure)
Outlook=Sunny (5 ex: 2Y3N, ): Evaluate remaining (Temp,Humidity,Windy):
- Gain(Humidity)=0.971 (High 3:0Y3N , Normal 2:2Y0N → weighted 0) → Best = Humidity
- Humidity=High → Leaf No, Humidity=Normal → Leaf Yes
Outlook=Rainy (5 ex: 3Y2N): Evaluate:
- Windy: False 3:3Y0N , True 2:0Y2N → Weighted 0 → Gain → Best=Windy
- Humidity gain , Temp
- Windy=False → Leaf Yes, Windy=True → Leaf No
Final Tree:
Outlook? ├─ Sunny → Humidity? │ ├─ High → No (3) │ └─ Normal → Yes (2) ├─ Overcast → Yes (4) └─ Rainy → Windy? ├─ False → Yes (3) └─ True → No (2)This tree achieves 100% training accuracy (14/14). Equivalent textbook result; order of Humidity/Windy nodes may swap if tie but this is standard ID3 outcome. Information Gains shown above at each split.
Q9a. Write short note on: Logistic Regression and Sigmoid Function20257m
Unit 3: Classification & Regression
View this question on its own page →Write short note on: Logistic Regression and Sigmoid Function
Worked SolutionLogistic Regression and Sigmoid Function:
Logistic Regression:
Discriminative linear classifier for binary classification. Despite name, it's classification, not regression. Models posterior where is sigmoid.- Hypothesis:
- Decision: predict 1 if () else 0 — linear boundary.
- Loss: Binary cross-entropy (log loss) — convex MLE under Bernoulli.
- Gradient: $
abla J = \frac1m X^T (h-y)$, solved via SGD, Newton. - Regularization: prevents overfit.
- Multi-class extends via softmax (Multinomial Logistic).
- Interpretable: coefficients as log-odds ratio, = odds multiplier for unit feature increase.
- Use when need probabilities, linear separable, baseline for text, medical.
Sigmoid Function:
, shape S-curve , derivative .Properties: squashes real to (0,1), smooth, differentiable, but suffers vanishing gradient for large (near 0 or 1) — replaced by ReLU in deep hidden layers but still core for logistic output, gating (LSTM).
Example: , , .
Together, sigmoid makes linear score interpretable as probability, optimized via cross-entropy, yielding calibrated classifier.