Machine Learning, Past Papers, UOS Main Campus

Machine Learning Past Paper 2016 – MS CS 3rd Term UOS (CS-5841)

ProgramMS CS
Term3rd
Year2016
Course codeCS-5841
AnswersSolved ✓

University of Sargodha MS Computer Science 3rd term Machine Learning (CS-5841) paper, 2016 exam (80 marks, 3 hours). The paper has been retyped, and solved answers are given below for all short questions and all six long questions, including neural networks for non-linear problems, Q-learning, entropy and information gain, and the 2-cluster K-means iterations.

Solved answers

Q1 – Short answers (8 × 2)

i. Overfitting: When a model learns the training data too closely, including its noise, so it has very low training error but high error on new (test) data. Prevented by more data, regularisation, pruning, cross-validation or early stopping.

ii. Recall: The fraction of actual positive cases that the model correctly finds: Recall = TP / (TP + FN). Also called sensitivity or true-positive rate.

iii. Conditional entropy: The remaining uncertainty of Y when X is known: H(Y|X) = −Σx p(x) Σy p(y|x) log2 p(y|x). Information gain = H(Y) − H(Y|X).

iv. Local minimum: A point where the cost (error) function is lower than at all nearby points but not necessarily the lowest overall (global minimum). Gradient descent can get stuck there.

v. Instance-based learning: “Lazy” learning that stores the training examples and classifies a new example by comparing it with stored ones (e.g. k-nearest neighbour, case-based reasoning); no explicit model is built in advance.

vi. Precision: The fraction of predicted positives that are actually positive: Precision = TP / (TP + FP).

vii. Accuracy: The fraction of all predictions that are correct: Accuracy = (TP + TN) / (TP + TN + FP + FN).

viii. Version space: The set of all hypotheses in the hypothesis space that are consistent with all the training examples seen so far; the Candidate-Elimination algorithm represents it by its most general (G) and most specific (S) boundaries.

Q2 – Neural networks for linear and non-linear problems; cost function

A single neuron (perceptron) computes y = f(w·x + b). Its decision boundary w·x + b = 0 is a straight line (hyperplane), so a single-layer network can classify only linearly separable problems such as AND and OR. It cannot solve XOR.

For non-linear problems a multilayer perceptron adds one or more hidden layers with non-linear activation functions (sigmoid, tanh, ReLU). Each hidden neuron draws one boundary and the output layer combines them, so the network can form curved or combined regions. For example, XOR is solved with two hidden neurons (one acting as OR, one as NAND) whose outputs are ANDed. By the universal approximation theorem, one hidden layer with enough neurons can approximate any continuous function.

Role of the cost function: it measures how far the network’s outputs are from the targets, e.g. mean squared error J = (1/2n) Σ (y − ŷ)² for regression or cross-entropy J = −Σ y log ŷ for classification. Training minimises J: back-propagation computes ∂J/∂w for every weight and gradient descent updates w ← w − η ∂J/∂w. The choice of cost function decides what “good” means, affects convergence speed and lets us add regularisation terms (e.g. λ‖w‖²) to reduce overfitting.

Q3 – Reinforcement learning and Q-learning

Reinforcement learning (RL) is learning by interaction: an agent observes a state s of the environment, takes an action a, receives a reward r and moves to a new state s′. It learns a policy π(s) that maximises the total discounted reward Σ γt rt. There is no labelled data; the agent must balance exploration and exploitation.

Q-learning algorithm (model-free):

Initialise Q(s, a) = 0 for all states and actions
repeat for each episode:
    s = start state
    repeat until s is terminal:
        choose a from s using ε-greedy (random with prob. ε, else argmax_a Q(s,a))
        take action a, observe reward r and next state s'
        Q(s,a) ← Q(s,a) + α [ r + γ · max_a' Q(s',a') − Q(s,a) ]
        s ← s'
Policy: π(s) = argmax_a Q(s,a)

Example: a robot in a 3-cell corridor A – B – C must reach C (reward +100, other moves 0), with α = 1 and γ = 0.9. After the first episodes Q(B, right) = 100, then Q(A, right) = 0 + 0.9 × 100 = 90. The learned policy is “move right” in A and B. Other RL algorithms: SARSA, TD(λ), policy gradient, Deep Q-Networks.

Q4 – Steps to introduce a new feature

  1. Identify the need / hypothesis: use domain knowledge or error analysis to decide what information is missing (e.g. “age of account” for fraud detection).
  2. Collect or derive the data: obtain it from a new source or construct it from existing features (ratios, differences, date parts, counts, interactions, polynomial terms).
  3. Clean it: handle missing values (impute), outliers and inconsistent units.
  4. Transform/encode: normalise or standardise numeric values; one-hot or label-encode categorical values; discretise if needed.
  5. Evaluate relevance: correlation, information gain, chi-square or mutual information with the target; check redundancy with existing features.
  6. Add to the dataset and retrain using the same train/validation split; compare performance with cross-validation.
  7. Keep or discard the feature depending on improvement; document it and apply the same transformation to new/test data (in a pipeline) to avoid data leakage.

Q5 – Supervised vs unsupervised learning

Supervised learningUnsupervised learning
Training data are labelled (input–output pairs)Data are unlabelled
Goal: learn a mapping to predict the label of new dataGoal: discover hidden structure, groups or patterns
Tasks: classification, regressionTasks: clustering, association rules, dimensionality reduction
Examples: decision trees, SVM, naïve Bayes, k-NN, linear regressionExamples: k-means, hierarchical clustering, Apriori, PCA
Accuracy can be measured directly against labelsEvaluation is harder (e.g. cluster cohesion, silhouette)

Incremental learning means updating the model as new examples arrive without retraining from scratch. Unsupervised methods are often more convenient because new data do not need labels (e.g. online/sequential k-means updates a centroid as each point arrives). However, many supervised learners are also naturally incremental (naïve Bayes count updates, perceptron/SGD, k-NN). In practice, when labels are available for the stream, incremental supervised learners give directly usable predictions; when labels are costly, unsupervised incremental learning is better suited.

Q6 – Entropy and information gain in classification

Entropy measures the impurity (uncertainty) of a set S of examples: H(S) = −Σ pi log2 pi. It is 0 when all examples belong to one class and maximum (1 for two classes) when the classes are equally mixed.

Information gain is the reduction in entropy obtained by splitting S on attribute A: Gain(S, A) = H(S) − Σv (|Sv|/|S|) H(Sv). Decision-tree algorithms (ID3, C4.5) choose, at each node, the attribute with the highest gain, so the tree separates the classes as quickly as possible and stays small.

Example: 14 examples with 9 Yes and 5 No: H = −(9/14)log2(9/14) − (5/14)log2(5/14) = 0.940. Splitting on Outlook gives subsets with entropies 0.971, 0 and 0.971 (sizes 5, 4, 5), so Gain = 0.940 − (5/14)(0.971) − 0 − (5/14)(0.971) = 0.247 – the highest, so Outlook becomes the root. C4.5 uses gain ratio to avoid bias towards attributes with many values.

Q7 – Clustering the 8 points with K = 2 (2 iterations)

With “K = 2” and “iterations” the question describes K-means clustering (k-NN has no iterations). Take the first two points as initial centroids: C1 = (2, 3), C2 = (4, 5). Euclidean distance is used.

PointIteration 1: d to C1 (2,3)d to C2 (4,5)ClusterIteration 2: d to C1 (2.5,3.5)d to C2 (4.17,7)Cluster
(2,3)02.8310.714.551
(4,5)2.83022.122.012
(3,7)4.122.2423.541.172
(4,8)5.393.0024.741.012
(2,8)5.003.6124.532.392
(3,4)1.411.411 (tie)0.713.221
(5,6)4.241.4123.541.302
(7,8)7.074.2426.363.002

After iteration 1: C1 = mean{(2,3), (3,4)} = (2.5, 3.5); C2 = mean{(4,5), (3,7), (4,8), (2,8), (5,6), (7,8)} = (25/6, 42/6) = (4.17, 7). Iteration 2 gives the same assignment, so the centroids do not change and the algorithm has converged: Cluster 1 = {(2,3), (3,4)}, Cluster 2 = {(4,5), (3,7), (4,8), (2,8), (5,6), (7,8)}. (In iteration 1, (3,4) is at equal distance √2 from both centroids; the tie is given to C1. Computed in Python.) On the 2-D grid, cluster 1 is the two points at the lower left and cluster 2 is the group in the upper part.

Save this paper for offline studyDownload the question paper, or save the paper together with all solved answers as a PDF.
↓ Download Paper (JPG)

About Saif R

An educator and technology enthusiast passionate about empowering students through quality education and digital learning. Dedicated to making academic resources and opportunities accessible to everyone.