Chapter 4
Machine Learning
TU BCA past exam questions
Past questions and answers
30 questions set from this chapter. Most repeated first.
- 2022 · 5 marks
What is Machine learning? Describe the types of learning.
Answer
Machine learning is a branch of artificial intelligence in which a computer learns patterns from data and improves its performance on a task with experience, without being explicitly programmed with rules. Formally (Mitchell): a program learns from experience with respect to task and performance measure if its performance on , measured by , improves with .
Types of learning
- Supervised learning: The training data contains inputs together with the correct labels. The model learns a mapping . Classification (spam or not spam) predicts discrete labels and regression (house price) predicts continuous values. Examples: linear regression, decision tree, SVM, Naive Bayes, k-NN.
- Unsupervised learning: The data has no labels. The model finds hidden structure such as clusters or lower-dimensional representations. Examples: k-means, hierarchical clustering, PCA, association rules.
- Semi-supervised learning: A small amount of labelled data is combined with a large amount of unlabelled data (e.g. image classification with few labelled photos).
- Reinforcement learning: An agent interacts with an environment, takes actions and receives rewards or penalties. It learns a policy that maximises cumulative reward (game playing, robotics, self-driving).
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2022 · 5 marks
What is clustering? Describe the approaches used for clustering.
Answer
Clustering is an unsupervised learning technique that groups unlabelled data objects into clusters so that objects in the same cluster are highly similar to each other and dissimilar to objects in other clusters. Similarity is usually measured by a distance such as Euclidean distance. Uses include customer segmentation, document grouping and image segmentation.
Approaches to clustering
- Partitioning methods: Divide objects into clusters (k is given in advance) and iteratively improve the partition, e.g. k-means and k-medoids.
- Hierarchical methods: Build a tree of clusters (dendrogram). Agglomerative (bottom-up) merges the closest clusters step by step; divisive (top-down) splits one big cluster repeatedly.
- Density-based methods: Clusters are dense regions separated by sparse regions. They find arbitrary-shaped clusters and handle noise, e.g. DBSCAN, OPTICS.
- Grid-based methods: The space is divided into a grid of cells and clustering is done on cells, which is fast, e.g. STING.
- Model-based methods: Assume data comes from a mixture of probability distributions and fit them, e.g. Gaussian Mixture Models with EM.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2022 · 5 marks
What is sensitivity and specificity? Describe Confusion matrix with example.
Answer
Sensitivity (recall, true positive rate) is the proportion of actual positives that the model correctly identifies:
Specificity (true negative rate) is the proportion of actual negatives that the model correctly identifies:
Confusion matrix is a table that compares actual classes with predicted classes of a classifier.
| Predicted Positive | Predicted Negative | |
|---|---|---|
| Actual Positive | TP (true positive) | FN (false negative) |
| Actual Negative | FP (false positive) | TN (true negative) |
Example: A disease test on 100 people gives TP = 40, FN = 10, FP = 5, TN = 45.
- Accuracy
- Sensitivity
- Specificity
- Precision
Thus the test detects 80% of the sick people and correctly clears 90% of the healthy ones.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2022 · 5 marks
What is linear regression? Explain gradient descent algorithm.
Answer
Linear regression is a supervised learning method that models the relationship between a dependent variable and one or more independent variables by fitting a straight line (hyperplane). For one feature the hypothesis is
The parameters are chosen to minimise the cost function (mean squared error):
Gradient descent is an iterative optimisation algorithm that finds the parameters minimising .
- Initialise (e.g. with 0 or random values).
- Choose learning rate .
- Repeat until convergence, updating all parameters simultaneously:
- Stop when stops decreasing noticeably or after a fixed number of iterations.
The gradient gives the direction of steepest increase, so moving opposite to it reduces the cost. If is too small, convergence is slow; if too large, the algorithm may overshoot and diverge. For linear regression is convex, so gradient descent reaches the global minimum. Variants are batch, stochastic and mini-batch gradient descent.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2022 · 5 marks
Describe training set, validation set and test set. Differentiate between training and testing.
Answer
- Training set: The portion of data used to fit the model, i.e. to learn the parameters (weights). Typically about 60-70%.
- Validation set: Data not used for fitting, used to tune hyperparameters (such as k, tree depth, learning rate), to select among models and to detect over-fitting. Typically 15-20%.
- Test set: Data kept completely unseen until the end, used once to estimate the final generalisation performance of the chosen model. Typically 15-20%.
Training vs testing
| Training | Testing |
|---|---|
| The model learns patterns and parameters from labelled data. | The trained model is evaluated on unseen data. |
| Aim is to minimise training error. | Aim is to measure generalisation (accuracy, precision, recall). |
| Parameters are updated. | Parameters are fixed. |
| Uses the larger part of the dataset. | Uses a smaller, separate part. |
| Takes more time and computation. | Quick, only prediction is done. |
| High training accuracy alone may mean over-fitting. | Test accuracy shows how the model performs in real use. |
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2022 · 5 marks
Describe line of best fit.
Answer
The line of best fit is the straight line that best represents the relationship between two variables in a scatter plot. It passes as close as possible to all the data points and is used to predict for a given .
It is found by the least squares method, which minimises the sum of squared residuals , where the residual is the vertical distance between an observed point and the line. The coefficients are
Properties
- It always passes through the mean point .
- The sum of residuals is zero.
- Slope shows the change in per unit change in ; the intercept is the value of at .
- The closeness of fit is measured by the correlation coefficient or .
Example: For points (1,2), (2,4), (3,5), (4,6), (5,8): , , , so the line is .
In machine learning the same line is obtained by linear regression using the normal equation or gradient descent.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2022 · 5 marks
What is naive bayes algorithm? How does it work? What are its merits and demerits?
Answer
Naive Bayes is a probabilistic supervised classifier based on Bayes' theorem with the "naive" assumption that all features are conditionally independent given the class.
How it works
For a class and feature vector :
With independence assumed,
Steps:
- Compute the prior of each class from training data.
- Compute the likelihood of each feature value for each class (use Laplace smoothing to avoid zero probabilities).
- For a new instance, compute for every class.
- Predict the class with the largest value (the denominator is common and can be ignored).
Merits
- Simple, very fast to train and predict.
- Works well with small training data and high-dimensional data (text, spam filtering).
- Handles multi-class problems and both discrete and continuous features.
Demerits
- The independence assumption rarely holds in real data.
- Zero-frequency problem unless smoothing is used.
- Probability estimates are often poor; continuous features need distribution assumptions (e.g. Gaussian).
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2022 · 10 marks
How does k-means algorithm work? Suppose following data k = 2 use k-means algorithm to cluster O1(1, 1.5), O2(1, 4.5), O3(2, 1.5), O4(2, 3.5), O5(3, 2.5), O6(3, 4)
Answer
K-means algorithm
- Choose the number of clusters and select initial centroids.
- Assign each object to the nearest centroid (Euclidean distance).
- Recompute each centroid as the mean of the objects assigned to it.
- Repeat steps 2-3 until the assignments (centroids) no longer change.
Solution (): take and as the initial centroids .
Iteration 1 (distances to and )
| Object | d to C1 | d to C2 | Cluster |
|---|---|---|---|
| O1 (1,1.5) | 0 | 3.00 | C1 |
| O2 (1,4.5) | 3.00 | 0 | C2 |
| O3 (2,1.5) | 1.00 | 3.16 | C1 |
| O4 (2,3.5) | 2.24 | 1.41 | C2 |
| O5 (3,2.5) | 2.24 | 2.83 | C1 |
| O6 (3,4) | 3.20 | 2.06 | C2 |
New centroids:
Iteration 2 (distances to and )
| Object | d to C1 | d to C2 | Cluster |
|---|---|---|---|
| O1 | 1.05 | 2.69 | C1 |
| O2 | 2.85 | 1.12 | C2 |
| O3 | 0.33 | 2.50 | C1 |
| O4 | 1.67 | 0.50 | C2 |
| O5 | 1.20 | 1.80 | C1 |
| O6 | 2.46 | 1.00 | C2 |
The assignments are unchanged, so the algorithm has converged.
Final clusters: Cluster 1 = {O1, O3, O5} with centroid (2, 1.83); Cluster 2 = {O2, O4, O6} with centroid (2, 4.0).
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2022 · 10 marks
What is perceptron? Explain back propagation algorithm with suitable example.
Answer
Perceptron
A perceptron is the simplest artificial neuron and a linear binary classifier. It computes a weighted sum of inputs plus bias and passes it through a step activation:
Learning rule: , where is the target and the learning rate. It can only solve linearly separable problems (AND, OR but not XOR). Multi-layer perceptrons overcome this using hidden layers and the back propagation algorithm.
Back propagation algorithm
Back propagation trains a multilayer feed-forward network by gradient descent on the error, propagating the error backward from output to input.
- Initialise weights and biases with small random values.
- Forward pass: for each training example, compute hidden outputs and then output outputs , with .
- Compute error at the output: .
- Backward pass: for each hidden unit , .
- Update weights: and biases .
- Repeat for all examples (epochs) until the error is small enough.
Example: Network with inputs , one hidden neuron with , , and an output neuron with , , target , .
- Forward: , ; , .
- Output error: .
- Hidden error: .
- Updates: ; ; stays 0.4 (since ).
The next forward pass gives an output closer to 1, so the error decreases.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2022 · 10 marks
How does SVM works? Describe functional margin, geometric margin and optimum margin classifier. Show the relationship between functional and geometrical margin.
Answer
How SVM works
A Support Vector Machine is a supervised classifier that finds the hyperplane that separates two classes with the maximum margin. Points closest to the hyperplane are the support vectors; only they determine the boundary. For non-separable data, a soft margin (parameter ) allows some errors, and the kernel trick (polynomial, RBF) maps the data to a higher-dimensional space where a linear separation is possible. Prediction: class if , else .
Functional margin
For a training example with :
A large positive value means a confident and correct prediction. For the training set it is . It can be made arbitrarily large by scaling , so it is not a true distance.
Geometric margin
The actual Euclidean distance of a point from the hyperplane:
It is invariant to scaling of .
Relationship
If the two margins are equal.
Optimum margin classifier
It chooses to maximise the geometric margin . Fixing the functional margin (by scaling), maximising is equivalent to the convex quadratic problem
Solved through its Lagrangian dual, where only for support vectors. The resulting classifier has the widest possible gap between the classes and hence good generalisation.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 · 5 marks
What constitutes over-fitting, and how can it be prevented? Elaborate with a suitable example.
Answer
Over-fitting occurs when a model learns the training data too well, including its noise and random fluctuations, so it has very low training error but high error on unseen data. It happens when the model is too complex relative to the amount of data (high variance, low bias). It is identified by a large gap between training and validation/test accuracy.
Example: Fitting a degree-9 polynomial through 10 noisy points lying roughly on a line gives zero training error, but the curve wiggles wildly and predicts new points badly, whereas a straight line generalises well. Similarly, a decision tree grown until every leaf is pure may memorise the training set and give 100% training but 70% test accuracy.
Prevention
- Collect more training data.
- Use a simpler model (fewer features, lower polynomial degree, smaller network).
- Regularisation (L1/L2 penalty on weights, dropout in neural networks).
- Cross-validation and a separate validation set to tune hyperparameters.
- Early stopping when validation error starts rising.
- Pruning for decision trees.
- Feature selection or dimensionality reduction.
- Ensemble methods such as bagging and random forests.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 · 5 marks
Define perceptron. Explain K-means clustering algorithm.
Answer
Perceptron
A perceptron is a single artificial neuron and the simplest linear binary classifier. It takes inputs with weights and bias , and outputs
Weights are learned with , where is the target output and the learning rate. It converges only if the classes are linearly separable.
K-means clustering
K-means is an unsupervised partitioning algorithm that divides data into clusters.
- Select and choose initial centroids (randomly).
- Assign every point to the nearest centroid using Euclidean distance.
- Recompute each centroid as the mean of its assigned points.
- Repeat steps 2 and 3 until centroids stop changing (or a maximum number of iterations is reached).
It minimises the within-cluster sum of squares . It is simple and fast, but needs in advance, is sensitive to initial centroids and outliers, and finds only spherical clusters.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 · 5 marks
Discuss the strengths and weaknesses of the Naive Bayes algorithm compared to other classification algorithms like Support Vector Machines.
Answer
Naive Bayes
Strengths
- Very fast training and prediction; needs only counting of frequencies.
- Works well with small datasets and very high-dimensional data such as text classification and spam filtering.
- Naturally multi-class and gives probabilistic outputs.
- Few hyperparameters and little tuning.
Weaknesses
- The conditional independence assumption is rarely true; correlated features reduce accuracy.
- Zero-probability problem unless smoothing is used.
- Cannot learn interactions between features.
- Probability estimates are poorly calibrated.
Comparison with SVM
| Aspect | Naive Bayes | SVM |
|---|---|---|
| Type | Generative, probabilistic | Discriminative, maximum-margin |
| Training speed | Very fast, linear | Slower (quadratic or worse) for large data |
| Feature dependence | Assumes independence | Handles dependent features |
| Non-linear data | Limited | Handled using kernels |
| Accuracy | Lower on complex data, good on small data | Usually higher on complex, high-dimensional data |
| Probabilities | Direct output | Not direct (needs calibration) |
| Tuning | Almost none | Needs choice of kernel, , |
| Noise/outliers | Fairly robust | Sensitive in the hard-margin case |
Naive Bayes is preferred for quick baselines and small or text data; SVM for higher accuracy when features are interdependent.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 · 5 marks
Why dimensionality reduction is useful? Considering a Long List of Machine Learning Algorithms, given a Data Set, How Do You Decide Which One to Use? Justify your answer.
Answer
Why dimensionality reduction is useful
- Reduces the curse of dimensionality: with many features, data becomes sparse and models over-fit.
- Lowers storage, memory and training time.
- Removes redundant, correlated and noisy features, improving accuracy.
- Makes visualisation possible by reducing data to 2D or 3D.
- Makes models simpler and easier to interpret.
Methods: PCA, LDA, t-SNE, feature selection.
Choosing an algorithm for a given data set
No single algorithm is best (no free lunch), so the choice is guided by the data and the problem:
- Type of problem: labelled target with categories gives classification, numeric target gives regression, no labels gives clustering or dimensionality reduction, sequential decisions give reinforcement learning.
- Size of data: small data suits Naive Bayes, linear models, k-NN; large data suits neural networks, gradient boosting.
- Number and type of features: many features suit linear models, SVM or regularised models; mixed categorical features suit decision trees.
- Linearity: linear relationship gives linear/logistic regression; non-linear gives SVM with kernel, trees, neural networks.
- Interpretability needed: decision trees and linear models over black-box models.
- Speed and resources for training and prediction.
- Experimentation: try a few candidate models, compare them by cross-validation using suitable metrics (accuracy, F1, RMSE), tune hyperparameters and pick the best one that does not over-fit.
This justifies choosing by data characteristics plus empirical validation rather than by a fixed rule.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 · 5 marks
What do you mean by ROC curve? In a credit card fraud detection system, the algorithm flagged 50 transactions as fraudulent. Out of these flagged transactions, 45 were indeed fraudulent. Additionally, the algorithm didn't flag 30 fraudulent transactions. Calculate the precision, recall and F1-score for the fraud detection system.
Answer
ROC curve
The Receiver Operating Characteristic (ROC) curve plots the True Positive Rate (sensitivity, ) on the y-axis against the False Positive Rate () on the x-axis for all possible classification thresholds. A curve close to the top-left corner indicates a good classifier; the diagonal represents random guessing. The area under the curve (AUC) summarises performance: 1 is perfect, 0.5 is no better than chance.
Fraud detection calculation
- Flagged as fraud = 50, of which truly fraud: , so .
- Fraudulent transactions not flagged: .
So precision is 90%, recall 60% and F1-score 0.72. The system is accurate when it flags, but misses 40% of the frauds.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 · 5 marks
What do you mean by hierarchical clustering? How can regression be used to find best fit line?
Answer
Hierarchical clustering builds a hierarchy (tree) of clusters, shown as a dendrogram, without needing the number of clusters in advance.
- Agglomerative (bottom-up): start with each object as its own cluster; repeatedly merge the two closest clusters until one cluster remains.
- Divisive (top-down): start with all objects in one cluster; repeatedly split until each object is separate.
Distance between clusters is measured by single linkage (minimum), complete linkage (maximum), average linkage or centroid distance. Cutting the dendrogram at a chosen height gives the desired number of clusters.
Using regression to find the best-fit line
Linear regression models and finds the parameters that minimise the sum of squared errors between actual and predicted values:
Setting the partial derivatives to zero gives
(or the same result is reached iteratively by gradient descent). The resulting line passes through and is the line of best fit, which can then predict for new .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 · 5 marks
Write short notes on (any two):
a) Supervised Vs. Unsupervised Learning
b) Sensitivity and Specificity
c) Bayesian Belief Network
Answer
(a) Supervised vs. unsupervised learning
| Supervised | Unsupervised |
|---|---|
| Uses labelled data (input and known output). | Uses unlabelled data. |
| Learns a mapping from inputs to outputs. | Discovers hidden structure or patterns. |
| Tasks: classification, regression. | Tasks: clustering, dimensionality reduction, association. |
| Algorithms: linear regression, decision tree, SVM, k-NN. | Algorithms: k-means, hierarchical clustering, PCA. |
| Accuracy can be measured directly. | Evaluation is harder and more subjective. |
| Example: predicting spam emails. | Example: grouping customers by behaviour. |
(b) Sensitivity and specificity
Sensitivity (true positive rate) is the fraction of actual positives correctly detected, . Specificity (true negative rate) is the fraction of actual negatives correctly identified, . They are derived from the confusion matrix and are used especially in medical testing: a highly sensitive test rarely misses disease, a highly specific test rarely gives false alarms. Raising one usually lowers the other, as shown on the ROC curve.
(c) Bayesian belief network
A Bayesian belief network is a directed acyclic graph in which nodes represent random variables and edges represent conditional (causal) dependencies. Each node has a conditional probability table . The joint probability is
It allows reasoning under uncertainty, such as computing the probability of disease given symptoms, and unlike Naive Bayes it permits dependencies between variables.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 · 10 marks
What is the need of confusion matrix? Explain the frame work for building machine learning system.
Answer
Need of the confusion matrix
Accuracy alone can be misleading, especially for imbalanced data (a model predicting "no fraud" always can be 99% accurate). The confusion matrix tabulates actual versus predicted classes:
| Predicted Positive | Predicted Negative | |
|---|---|---|
| Actual Positive | TP | FN |
| Actual Negative | FP | TN |
It is needed because
- it shows the types of errors (false positives and false negatives), which have different costs;
- it allows computing accuracy , precision , recall , specificity and F1-score;
- it shows which classes are confused with each other in multi-class problems;
- it helps compare models and choose thresholds.
Framework for building a machine learning system
- Problem definition: state the goal, the task type (classification, regression, clustering) and the success metric.
- Data collection: gather relevant data from databases, sensors, web, surveys.
- Data preparation (pre-processing): clean missing values, noise and duplicates; encode categorical data; scale/normalise.
- Exploratory analysis and feature engineering: visualise, select, extract or reduce features.
- Splitting data: into training, validation and test sets.
- Model selection and training: choose candidate algorithms and fit them to the training set.
- Evaluation and tuning: assess on validation data (cross-validation, confusion matrix, ROC) and tune hyperparameters; handle over/under-fitting.
- Testing: measure final performance on the unseen test set.
- Deployment: integrate the model into an application or service.
- Monitoring and maintenance: track performance, detect data drift and retrain with new data.
The process is iterative; results at later steps often send the developer back to earlier steps.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 · 10 marks
Define entropy and information gain. Construct decision tree (ID3 Algorithm)for the following:DayOutlookTemperatureHumidityWindDecision
1SunnyHotHighWeakYes
2SunnyHotHighStrongNo
3OvercastHotHighWeakYes
4RainMildHighWeakNo
5RainColdNormalWeakYes
Answer
Entropy measures the impurity (uncertainty) of a set of examples:
It is 0 for a pure set and 1 for a two-class set split equally.
Information gain is the expected reduction in entropy after splitting on attribute :
ID3 selects, at each node, the attribute with the highest information gain.
Construction
Data: 3 Yes (days 1, 3, 5) and 2 No (days 2, 4).
Outlook: Sunny {Yes, No} gives ; Overcast {Yes} gives ; Rain {No, Yes} gives .
Temperature: Hot {Y, N, Y} gives ; Mild {N} gives ; Cold {Y} gives .
Humidity: High {Y, N, Y, N} gives ; Normal {Y} gives .
Wind: Weak {Y, Y, N, Y} gives ; Strong {N} gives .
Temperature has the highest gain (0.420), so it is the root.
- Mild gives No (pure).
- Cold gives Yes (pure).
- Hot contains days 1, 2, 3 {Y, N, Y}. Splitting by Wind: Weak (days 1, 3) gives Yes and Strong (day 2) gives No, so gain is highest and the subtree is pure.
Decision tree
Temperature
├── Mild -> No
├── Cold -> Yes
└── Hot -> Wind
├── Weak -> Yes
└── Strong -> No
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 · 10 marks
What are bias -variance trade off? Consider the table given below and use K-NN algorithm to evaluate result of Sija= {Machine Learning=60 GIS=80}DayOutlookTemperatureHumidityWindDecision
1SunnyHotHighWeakYes
2SunnyHotHighStrongNo
3OvercastHotHighWeakYes
4RainMildHighWeakNo
5RainColdNormalWeakYes
Answer
Bias-variance trade-off
The expected prediction error of a model can be decomposed as
- Bias is the error from wrong or over-simple assumptions; high bias causes under-fitting.
- Variance is the sensitivity of the model to small changes in the training data; high variance causes over-fitting.
Making a model more complex lowers bias but raises variance, and a simpler model does the opposite. The trade-off is to choose the complexity that minimises total error, usually found with validation.
K-NN algorithm
- Choose .
- Compute the distance (Euclidean) between the query and each training example.
- Take the nearest examples.
- Predict the majority class (or the average for regression).
Applying it to the table
The query Sija is described by two numeric marks, but the given table has the categorical attributes Outlook, Temperature, Humidity and Wind, and contains no Machine Learning or GIS values. Distances between Sija and the five days therefore cannot be computed from the table as it stands. With the table's own attributes, a new day is classified as follows: encode each attribute, count the number of mismatching attributes (Hamming distance) to every day, pick the closest days (for example ) and take the majority of their Decision values. For a query with numeric attributes such as Sija, the distance to a training record would be , and the Decision of the majority of the nearest records would be assigned to Sija.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2025 · 2+3 marks
Explain the bias–variance trade-off in machine learning. Provide examples of how increasing model complexity affects both bias and variance.
Answer
Bias-variance trade-off
The expected error of a model on unseen data is
- Bias is the error caused by overly simple assumptions (under-fitting).
- Variance is the error caused by sensitivity to the particular training sample (over-fitting).
The trade-off: lowering one tends to raise the other, so the best model balances the two to minimise total error.
Effect of increasing complexity
- Low complexity: a linear model fitted to curved (quadratic) data has high bias and low variance. It under-fits and gives high error on both training and test data.
- Moderate complexity: a degree-2 polynomial matches the true pattern; bias and variance are both low, so test error is lowest.
- High complexity: a degree-10 polynomial or a very deep decision tree fits the training noise: bias is very low, variance is high, training error is near zero but test error rises.
So as complexity increases, bias decreases and variance increases. Test error is U-shaped, and the optimum is at the bottom of the U. Regularisation, more data and cross-validation help control it.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2025 · 3+2 marks
Describe the decision tree algorithm. What are the advantages and disadvantages of using decision trees?
Answer
Decision tree algorithm
A decision tree is a supervised model (classification and regression) that represents decisions as a tree: internal nodes test an attribute, branches are the outcomes of the test, and leaf nodes hold the class label or value.
Building (top-down, recursive, e.g. ID3, C4.5, CART):
- Start with all training examples at the root.
- Select the best attribute using a splitting measure: information gain (entropy) in ID3, gain ratio in C4.5, or Gini index in CART.
- Split the data by the attribute's values into child nodes.
- Repeat recursively on each child until the node is pure, no attributes remain, or a stopping condition is met.
- Prune the tree to avoid over-fitting.
To classify a new example, follow the tests from the root to a leaf.
Advantages
- Easy to understand and interpret; can be visualised and converted to rules.
- Handles numeric and categorical data with little pre-processing (no scaling).
- Captures non-linear relationships and feature interactions.
- Fast prediction.
Disadvantages
- Prone to over-fitting without pruning.
- Unstable: small changes in data can produce a very different tree.
- Greedy splitting may not give the globally optimal tree.
- Biased toward attributes with many values; poor for imbalanced classes.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2025 · 5 marks
Discuss the structure and learning process of a neural network in supervised learning.
Answer
Structure of a neural network
An artificial neural network consists of layers of interconnected neurons:
- Input layer: one neuron per feature; passes the inputs on.
- Hidden layer(s): neurons compute using weights , bias and a non-linear activation (sigmoid, tanh, ReLU).
- Output layer: produces the prediction (sigmoid or softmax for classes, linear for regression).
Each connection has a weight; the weights and biases are the parameters learned.
Learning process in supervised learning
- Initialise weights randomly.
- Forward propagation: feed a training input through the layers to get the predicted output .
- Compute loss: compare with the true label using a loss function such as mean squared error or cross-entropy.
- Back propagation: propagate the error backward using the chain rule to compute the gradient of the loss with respect to every weight.
- Update weights by gradient descent: , with learning rate .
- Repeat over all training examples (epochs, usually in mini-batches) until the loss converges or validation error stops improving.
Finally the network is evaluated on unseen test data; regularisation, dropout and early stopping reduce over-fitting.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2025 · 2.5+2.5 marks
The ages of 10 employees in a company are:
22, 25, 29, 30, 31, 33, 35, 36, 40, 45
a. Find minimum, Q1, median, Q3, and maximum values.
b. Draw a box plot for the data.
Answer
(a) Data (already sorted, ): 22, 25, 29, 30, 31, 33, 35, 36, 40, 45
- Minimum
- Maximum
- Median (average of the 5th and 6th values)
- = median of the lower half (22, 25, 29, 30, 31)
- = median of the upper half (33, 35, 36, 40, 45)
Five-number summary: 22, 29, 32, 36, 45. .
Outlier fences: and ; all values lie inside, so there are no outliers.
(b) Box plot (on an age scale):
age: 20 25 30 35 40 45
|-----[=====|====]-------------|
22 29 32 36 45
min Q1 median Q3 max
The box extends from to with a line at the median 32. The whiskers extend to the minimum 22 on the left and the maximum 45 on the right. The longer right whisker shows slight positive skew.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2025 · 5 marks
A spam filter uses the words "offer" and "win" as features.
From training data:
ClassP(offer)P(win)Prior Probability
Spam0.80.60.4
Not Spam0.10.050.6
Given an email containing both words, classify it as Spam or Not Spam using Naïve Bayes.
Answer
Naive Bayes: (features assumed independent).
Spam:
Not Spam:
Normalising with :
Since , the email is classified as Spam (about 98.5% probability).
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2025 · 5 marks
Explain the steps of the Principal Component Analysis (PCA) algorithm.
Answer
Principal Component Analysis (PCA) is an unsupervised dimensionality-reduction technique that transforms correlated features into a smaller set of uncorrelated variables (principal components) that retain most of the variance.
Steps
- Standardise the data: subtract the mean of each feature (and divide by the standard deviation if scales differ) so each feature has mean 0.
- Compute the covariance matrix of the features:
- Compute eigenvalues and eigenvectors of by solving (or use SVD). Eigenvectors give the directions of the components; eigenvalues give the variance along them.
- Sort eigenvectors by decreasing eigenvalue.
- Select the top components that explain enough variance (e.g. 95%), using the explained variance ratio .
- Form the projection matrix from the chosen eigenvectors.
- Transform the data: , giving the new dataset.
The first component captures the maximum variance, the second is orthogonal to it and captures the next largest, and so on.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2025 · 5 marks
Perform one iteration of K-means clustering for the following points with initial centroids C1 = (1,1) and C2 = (5,4): Points: (1,1), (2,1), (4,3), (5,4). Use Euclidean distance.
Answer
Initial centroids: , .
Assignment step (Euclidean distance)
| Point | d to C1 (1,1) | d to C2 (5,4) | Cluster |
|---|---|---|---|
| (1,1) | 0 | C1 | |
| (2,1) | C1 | ||
| (4,3) | C2 | ||
| (5,4) | 0 | C2 |
Update step
After one iteration: Cluster 1 = {(1,1), (2,1)} with centroid (1.5, 1); Cluster 2 = {(4,3), (5,4)} with centroid (4.5, 3.5).
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2025 · 6+4 marks
Describe the Support Vector Machine (SVM) concept of maximum margin classification with a diagram. A model trained on a dataset achieves the following results:
Training accuracy: 95%
Validation accuracy: 80%
Test accuracy: 78%
Discuss whether the model is underfitting, overfitting, or well-fitted. Justify your answer.
Answer
SVM maximum margin classification
SVM finds, among all hyperplanes that separate the two classes, the one with the maximum margin, i.e. the largest distance to the nearest training points of either class. The nearest points are the support vectors; they lie on the margin hyperplanes , and the margin width is . Maximising it is equivalent to
A larger margin gives better generalisation. Non-separable data uses a soft margin (parameter ) or kernels.
x2
| o o (class +1)
| o \ w.x+b = +1
| ----------\----------- w.x+b = 0 (max-margin hyperplane)
| x x \ w.x+b = -1
| x (class -1)
+------------------------- x1
(support vectors lie on the dashed margin lines;
margin width = 2/||w||)
Fit analysis
Training accuracy 95%, validation 80% and test 78%.
- The training accuracy is high, so the model is not under-fitting (under-fitting would show low accuracy on training data too).
- There is a large gap (about 15-17 points) between training and validation/test accuracy, while validation and test are close to each other.
Hence the model is over-fitted: it has memorised the training data, including noise, and generalises poorly. The close validation and test scores show the drop is consistent, not an accident of one split. Remedies: regularisation, simpler model, more data, cross-validation, early stopping, feature reduction. A well-fitted model would show training and validation accuracies both high and close together.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2025 · 3+7 marks
Explain the concept of Confusion Matrix with example. Given the dataset below, fit a linear regression model using the least squares method and find the best-fit line equation. Also find the value of Y at X=4.5
XY
12
24
35
46
58
Answer
Confusion matrix
A confusion matrix is a table that summarises the performance of a classifier by comparing actual and predicted classes.
| Predicted Positive | Predicted Negative | |
|---|---|---|
| Actual Positive | TP | FN |
| Actual Negative | FP | TN |
Example: A spam filter classifies 100 emails: TP = 40, FN = 10, FP = 5, TN = 45. Then accuracy , precision , recall .
Linear regression by least squares
| 1 | 2 | -2 | -3 | 6 | 4 |
| 2 | 4 | -1 | -1 | 1 | 1 |
| 3 | 5 | 0 | 0 | 0 | 0 |
| 4 | 6 | 1 | 1 | 1 | 1 |
| 5 | 8 | 2 | 3 | 6 | 4 |
| Sum | 14 | 10 |
Best-fit line:
At :
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2025 · 6+4 marks
Explain the K-nearest neighbor (KNN) algorithm. How does the value of k affect bias and variance?
Given two classes of points:
Class +1: (2, 2), (4, 4)
Class −1: (4, 0), (0, 0)
Determine the equation of the separating hyper-plane.
Answer
K-nearest neighbour (KNN)
KNN is a simple, instance-based (lazy) supervised algorithm. To classify a query point:
- Choose and a distance measure (usually Euclidean).
- Compute the distance from the query to all training points.
- Select the nearest points.
- Predict the majority class (or the average value for regression).
No model is built during training; all the work is done at prediction time.
Effect of on bias and variance
- Small (e.g. 1): the boundary is very flexible and follows noise, so low bias, high variance (over-fitting).
- Large : predictions are averaged over many neighbours and the boundary is smooth, so high bias, low variance (under-fitting). If , it always predicts the majority class.
is chosen by cross-validation, usually odd to avoid ties.
Separating hyperplane
Class : (2,2), (4,4); class : (4,0), (0,0). The maximum-margin hyperplane has support vectors (2,2), (4,0), (0,0). Writing for (2,2) and for the negatives:
- (0,0):
- (4,0):
- (2,2):
So , . Check (4,4): , so it is correctly classified. Dual check: gives for (2,2), for (4,0), and for (0,0), all positive and balanced ().
The margin is .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
Questions from TU BCA 2022 Eighth Semester Database Programming (TU board exam, 2022), TU BCA 2023 Eighth Semester Database Programming (TU board exam, 2023), TU BCA 2024 Eighth Semester Database Programming (TU board exam, 2024), TU BCA 2025 Eighth Semester Database Programming (TU board exam, 2025), TU BCA 2022 Eighth Semester Geographical Information System (TU board exam, 2022), TU BCA 2023 Eighth Semester Geographical Information System (TU board exam, 2023), TU BCA 2024 Eighth Semester Geographical Information System (TU board exam, 2024), TU BCA 2025 Eighth Semester Geographical Information System (TU board exam, 2025), TU BCA 2022 Eighth Semester Information Security (TU board exam, 2022), TU BCA 2023 Eighth Semester Information Security (TU board exam, 2023), TU BCA 2024 Eighth Semester Information Security (TU board exam, 2024), TU BCA 2025 Eighth Semester Information Security (TU board exam, 2025), TU BCA 2022 Eighth Semester Machine Learning (TU board exam, 2022), TU BCA 2023 Eighth Semester Machine Learning (TU board exam, 2023), TU BCA 2025 Eighth Semester Machine Learning (TU board exam, 2025), TU BCA 2022 Eighth Semester Operational Research (TU board exam, 2022), TU BCA 2023 Eighth Semester Operational Research (TU board exam, 2023), TU BCA 2024 Eighth Semester Operational Research (TU board exam, 2024) and TU BCA 2025 Eighth Semester Operational Research (TU board exam, 2025). Answers are written for this site; check them against your class notes.