0% found this document useful (0 votes)
5 views20 pages

MCQ Questions for ML Interview Prep

This document is a comprehensive guide for preparing for machine learning interviews, covering multiple-choice questions (MCQs) across various topics including Genetic Algorithms, Supervised Learning, Unsupervised Learning, Neural Networks, Ensemble Learning, and other ML concepts. Each question is followed by the correct answer and a brief explanation. The content is structured to help candidates understand key concepts and prepare effectively for interviews.

Uploaded by

sololeveler11
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views20 pages

MCQ Questions for ML Interview Prep

This document is a comprehensive guide for preparing for machine learning interviews, covering multiple-choice questions (MCQs) across various topics including Genetic Algorithms, Supervised Learning, Unsupervised Learning, Neural Networks, Ensemble Learning, and other ML concepts. Each question is followed by the correct answer and a brief explanation. The content is structured to help candidates understand key concepts and prepare effectively for interviews.

Uploaded by

sololeveler11
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MCQ ML Interview Preparation

1. In GA, which of the following steps makes small


random changes to guarantee population diversity?
Selection
Crossover
Mutation
Fitness function

Mutation – Mutation introduces small random


changes to maintain population diversity.

2. Which of the following should be an example of a


fuzzy set?
Brazil belongs to the group of South American
Countries
A lion does not belong to the group of reptiles
Someone with one million belongs to the group of
rich people
French rose, or rose of Provins is a species of
flowering plant in the rose family.

Someone with one million belongs to the group of


rich people – This is an example of a fuzzy set
since "rich" is subjective and can vary.

3. Which of the following statements regarding ANN is


not true?
Deep learning is normally NN with many layers.
A NN can have only one or more than one output
unit, depending on your problem.
A complex NN (many layers) can model very complex
nonlinear functions.
Adding more layers to a NN is always better.

More layers can lead to overfitting, vanishing


gradients, and unnecessary complexity.

4. What does the One-Versus-All method in Logistic


Regression do?
Learn a classifier for each class, then pick the
decisions of the classifier of which the
probability value is the average among the
classifiers.

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

Learn a classifier for each class, then pick the


decisions of the classifier that gives the lowest
probability.
Learn a classifier for each class, then pick the
decisions of the classifier that gives the highest
probability.
Learn a classifier for each class, then pick the
decisions of the classifier that gives the discrete
probability.
One-Versus-All trains a separate classifier per
class and selects the one with the highest
probability.

5. What is the fitness function in GA?


A function that transforms a bad solution into a
good one (with more fitness).
A function that measures the fitness of a solution
(the more fitness, the better).
A function that removes solutions having the low
fitness values.
A function that is used to maintain genetic
algorithm diversity from one generation of a
population of genetic algorithm chromosomes to the
next.

The fitness function evaluates how good a solution


is.

6. “Individuals having more fitness will have more


chances to survive”, that is the general idea of
________________.
Mutation
Recombination
Selection
Fitness Function

Selection – In GA, selection favours individuals


with higher fitness, giving them a better chance
to pass their genes.

7. In GA, _____________________.

Each chromosome represents a solution.


Each gene represents a solution.

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

Each DNA represents a solution.


Each Protein represents a solution.

In GA, a chromosome encodes a possible solution.

8. What is Evolutionary Computation?


A biological field that applies AI algorithms to
understand the evolution theory.
A family of algorithms for global optimization
inspired by biological evolution.
A statistical study on how computers have evolved.
Used to find a linear combination of features that
characterises or separates two or more classes of
objects or events.
Evolutionary computation refers to optimization
techniques based on natural evolution.

9. What does Defuzzification do?


Convert truth values of input into a numeric value.
Convert truth values of output into a numeric
value.
Convert the numeric value of outputs into its truth
value.
None of the mentioned.

Defuzzification converts fuzzy output back into a


crisp value.

10. What does Fuzzification do?


Convert numeric input values into truth values
(degrees of membership).
Convert truth values of inputs into a numeric
value.
Use IF-THEN rules to infer possible outputs.
None of the mentioned.

Fuzzification converts precise inputs into fuzzy


values.

11. Given a population with 5 individuals having


the following fitness values:
f(c1) = 0.14
f(c2) = 0.45
f(c3) = 0.08

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

f(c4) = 0.86
f(c5) = 0.31

Step 1: Compute Total Fitness

𝐹𝑡𝑜𝑡𝑎𝑙 = 𝑓(𝑐1) + 𝑓(𝑐2) + 𝑓(𝑐3) + 𝑓(𝑐4) + 𝑓(𝑐5)


= 𝟎. 𝟏𝟒 + 𝟎. 𝟒𝟓 + 𝟎. 𝟎𝟖 + 𝟎. 𝟖𝟔 + 𝟎. 𝟑𝟏 = 𝟏. 𝟖𝟒

Step 2: Compute Selection Probability for Each Individual

Each individual’s selection probability is given by:

𝑓(𝑐𝑖)
𝑃(𝑐𝑖) =
𝐹𝑡𝑜𝑡𝑎𝑙
0.14
𝑃(𝑐1) = = 0.0761
1.84
0.45
𝑃(𝑐2) = = 0.2446
1.84
0.08
𝑃(𝑐3) = = 0.0435
1.84
0.86
𝑃(𝑐4) = = 0.4674
1.84
0.31
𝑃(𝑐5) = = 0.1685
1.84

Step 3: Compute Cumulative Probability (Roulette Wheel)

𝑪𝒖𝒎𝒖𝒍𝒂𝒕𝒊𝒗𝒆(𝒄𝟏) = 𝟎. 𝟎𝟕𝟔𝟏
𝑪𝒖𝒎𝒖𝒍𝒂𝒕𝒊𝒗𝒆(𝒄𝟐) = 𝟎. 𝟎𝟕𝟔𝟏 + 𝟎. 𝟐𝟒𝟒𝟔 = 𝟎. 𝟑𝟐𝟎𝟕
𝑪𝒖𝒎𝒖𝒍𝒂𝒕𝒊𝒗𝒆(𝒄𝟑) = 𝟎. 𝟑𝟐𝟎𝟕 + 𝟎. 𝟎𝟒𝟑𝟓 = 𝟎. 𝟑𝟔𝟒𝟐
𝑪𝒖𝒎𝒖𝒍𝒂𝒕𝒊𝒗𝒆(𝒄𝟒) = 𝟎. 𝟑𝟔𝟒𝟐 + 𝟎. 𝟒𝟔𝟕𝟒 = 𝟎. 𝟖𝟑𝟏𝟔
𝑪𝒖𝒎𝒖𝒍𝒂𝒕𝒊𝒗𝒆(𝒄𝟓) = 𝟎. 𝟖𝟑𝟏𝟔 + 𝟎. 𝟏𝟔𝟖𝟓 = 𝟏. 𝟎𝟎𝟎

Step 4: Selection Using Random Sampling

To simulate selection, random numbers (between 0 and 1) are generated.


Example random values: 0.15, 0.62, 0.85, 0.30, 0.45

• 0.15 → c2 (0.0761 to 0.3207)


• 0.62 → c4 (0.3642 to 0.8316)
• 0.85 → c5 (0.8316 to 1.000)
• 0.30 → c2 (0.0761 to 0.3207)
• 0.45 → c4 (0.3642 to 0.8316)

Thus, the selected individuals: c2, c4, c5, c2, c4.

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

Final Answer:

Based on fitness proportionate selection, individuals c2 and c4 have a higher chance of


selection, while c3 has the least chance due to its low fitness.

Supervised Learning

1. Which of the following is true for supervised learning?


a) It requires labeled data
b) It does not need labeled data
c) It only works for categorical data
d) It is only used for reinforcement learning
Answer: a) It requires labeled data
2. Which algorithm is best suited for classifying emails as spam or not spam?
a) K-Means Clustering
b) Decision Trees
c) Naïve Bayes
d) PCA
Answer: c) Naïve Bayes (commonly used for text classification)
3. Which of the following is an example of regression?
a) Predicting house prices
b) Predicting customer churn (yes/no)
c) Identifying spam emails
d) Handwriting recognition
Answer: a) Predicting house prices
4. Which metric is NOT suitable for evaluating a regression model?
a) Mean Squared Error (MSE)
b) R² Score
c) Accuracy
d) Mean Absolute Error (MAE)
Answer: c) Accuracy (Accuracy is used for classification, not regression)
5. What happens if the learning rate in Gradient Descent is too high?
a) Model converges faster
b) Model may overshoot and never converge
c) Model will always find the global minimum
d) Model will be underfitting
Answer: b) Model may overshoot and never converge

Unsupervised Learning

6. Which algorithm is used for clustering?


a) Linear Regression
b) K-Means
c) Logistic Regression
d) Decision Trees
Answer: b) K-Means

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

7. Which method is used for dimensionality reduction?


a) Random Forest
b) PCA (Principal Component Analysis)
c) Gradient Boosting
d) KNN
Answer: b) PCA
8. What does the "K" in K-Means Clustering represent?
a) Number of features
b) Number of clusters
c) Number of observations
d) Number of nearest neighbors
Answer: b) Number of clusters
9. Which clustering algorithm does not require specifying the number of clusters
beforehand?
a) K-Means
b) DBSCAN
c) Hierarchical Clustering
d) Both b and c
Answer: d) Both b (DBSCAN) and c (Hierarchical Clustering)
10. Which of the following is NOT an unsupervised learning algorithm?
a) Hierarchical Clustering
b) DBSCAN
c) Logistic Regression
d) PCA
Answer: c) Logistic Regression (It is a supervised learning algorithm)

Neural Networks & Deep Learning

11. Which activation function suffers from the vanishing gradient problem?
a) ReLU
b) Sigmoid
c) Tanh
d) Both b and c
Answer: d) Both b (Sigmoid) and c (Tanh)
12. What is the main advantage of using ReLU over sigmoid activation?
a) Avoids vanishing gradient
b) Works only for classification
c) Always results in better accuracy
d) Uses more memory
Answer: a) Avoids vanishing gradient
13. Which type of Neural Network is best suited for time-series prediction?
a) CNN (Convolutional Neural Network)
b) RNN (Recurrent Neural Network)
c) Feedforward Neural Network
d) DBN (Deep Belief Network)
Answer: b) RNN
14. Which technique is used to prevent overfitting in deep learning models?
a) Dropout

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

b) Increasing the number of layers


c) Using the same data for training and testing
d) Increasing learning rate
Answer: a) Dropout
15. Which neural network layer is responsible for feature extraction in CNNs?
a) Fully connected layer
b) Pooling layer
c) Convolutional layer
d) ReLU layer
Answer: c) Convolutional layer

Ensemble Learning & Boosting

16. Which algorithm is an example of ensemble learning?


a) Random Forest
b) Decision Tree
c) Logistic Regression
d) KNN
Answer: a) Random Forest
17. What does boosting do in ensemble learning?
a) Train multiple models independently
b) Combine weak learners into a strong learner
c) Randomly selects data for training
d) Reduces the number of training samples
Answer: b) Combine weak learners into a strong learner
18. Which algorithm is NOT an example of boosting?
a) AdaBoost
b) XGBoost
c) Gradient Boosting
d) K-Means
Answer: d) K-Means (It is a clustering algorithm)
19. Which technique is used to train multiple weak learners on different subsets of
data?
a) Bagging
b) Boosting
c) Stacking
d) Cross-validation
Answer: a) Bagging
20. Which of the following is NOT a key advantage of ensemble learning?
a) Reduces overfitting
b) Improves accuracy
c) Makes models interpretable
d) Handles missing values better
Answer: c) Makes models interpretable (Ensemble models are complex)

Other ML Concepts

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

21. Which of the following is NOT a hyperparameter?


a) Learning Rate
b) Number of Hidden Layers
c) Weights of the Model
d) Batch Size
Answer: c) Weights of the Model (Weights are learned, not set beforehand)
22. What is the main purpose of cross-validation?
a) To reduce the dataset size
b) To find the best hyperparameters
c) To check model performance on different test sets
d) To speed up training
Answer: c) To check model performance on different test sets
23. What does L1 regularization (Lasso) do?
a) Shrinks some weights to zero
b) Penalizes large weights
c) Prevents overfitting
d) All of the above
Answer: d) All of the above
24. Which loss function is commonly used for classification?
a) Mean Squared Error (MSE)
b) Cross-Entropy Loss
c) Hinge Loss
d) Both b and c
Answer: d) Both b (Cross-Entropy) and c (Hinge for SVM)
25. What is the main purpose of the ROC curve?
a) Evaluate regression models
b) Compare classification models
c) Reduce dimensionality
d) None of the above
Answer: b) Compare classification models

Optimization & Gradient Descent

1. Which technique can help escape local minima in non-convex optimization


problems?
a) Using a higher learning rate
b) Stochastic Gradient Descent (SGD) with momentum
c) L1 Regularization
d) Increasing the dataset size
Answer: b) SGD with momentum (Momentum helps smooth out updates and
escape local minima)
2. What is the primary benefit of Adam Optimizer over traditional SGD?
a) Adaptive learning rate adjustment
b) Faster convergence for convex problems
c) Works only for deep networks
d) Requires fewer hyperparameters
Answer: a) Adaptive learning rate adjustment (Adam dynamically adapts the
learning rate using past gradients)
3. Which of the following is NOT an issue when training deep networks?
a) Vanishing gradients

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

b) Exploding gradients
c) Convex optimization
d) Overfitting
Answer: c) Convex optimization (Deep learning problems are usually non-
convex)
4. Which regularization technique adds a penalty proportional to the absolute
value of the coefficients?
a) L1 (Lasso)
b) L2 (Ridge)
c) Elastic Net
d) Batch Normalization
Answer: a) L1 (Lasso) (L1 leads to feature selection by shrinking some weights
to zero)
5. How does batch normalization improve training speed?
a) By normalizing inputs to zero mean and unit variance
b) By reducing the need for dropout
c) By eliminating vanishing gradients
d) By making the model deeper
Answer: a) By normalizing inputs to zero mean and unit variance (This stabilizes
training and allows larger learning rates)

Deep Learning & Neural Networks

6. Which of the following problems is best solved using an autoencoder?


a) Image classification
b) Anomaly detection
c) Object detection
d) Time series forecasting
Answer: b) Anomaly detection (Autoencoders learn to reconstruct normal data,
making anomalies stand out)
7. Which architecture is best suited for NLP tasks?
a) CNN
b) RNN
c) LSTM
d) Both b and c
Answer: d) Both b (RNN) and c (LSTM) (LSTM is a type of RNN that handles
long-term dependencies)
8. Which layer type in CNNs is responsible for reducing spatial dimensions?
a) Fully connected layer
b) Pooling layer
c) Convolutional layer
d) ReLU layer
Answer: b) Pooling layer (Pooling reduces feature map dimensions while
preserving important information)
9. Why does ReLU activation function perform better than sigmoid in deep
networks?
a) ReLU helps with vanishing gradients
b) Sigmoid works only for linear problems

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

c) ReLU requires less computation


d) Both a and c
Answer: d) Both a and c (ReLU mitigates vanishing gradients and is
computationally efficient)
10. What problem does Transformer architecture solve compared to RNNs?
a) Requires less data
b) Avoids vanishing gradient issues
c) Enables parallel processing for sequence data
d) Both b and c
Answer: d) Both b (avoids vanishing gradients) and c (allows parallelization with
self-attention)

Ensemble Learning & Advanced Models

11. Which ensemble learning technique averages multiple models' predictions?


a) Bagging
b) Boosting
c) Stacking
d) Reinforcement Learning
Answer: a) Bagging (Random Forest uses bagging to reduce variance)
12. Which ensemble method gives more weight to misclassified samples?
a) Bagging
b) Boosting
c) Stacking
d) PCA
Answer: b) Boosting (Boosting sequentially corrects errors by adjusting weights)
13. Which algorithm is used in XGBoost?
a) Gradient Boosting Trees
b) Random Forest
c) K-Means
d) Bayesian Networks
Answer: a) Gradient Boosting Trees (XGBoost is an optimized version of
GBDT)
14. What is the main advantage of Stacking over Bagging and Boosting?
a) Uses multiple base learners to learn a final model
b) Requires fewer data
c) Is computationally less expensive
d) Does not require training multiple models
Answer: a) Uses multiple base learners to learn a final model (Stacking combines
multiple models to learn a meta-model)
15. Which model is best suited for imbalanced classification problems?
a) Logistic Regression
b) Random Forest
c) SMOTE + XGBoost
d) PCA
Answer: c) SMOTE + XGBoost (SMOTE balances data, and XGBoost handles
complex decision boundaries)

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

Real-World ML Applications & Case Studies

16. Which model should be used for credit card fraud detection?
a) Logistic Regression
b) K-Means
c) Anomaly Detection with Autoencoders
d) PCA
Answer: c) Anomaly Detection with Autoencoders (Fraud detection deals with
rare events, which anomaly detection is well-suited for)
17. Which algorithm is best for recommendation systems?
a) K-Means
b) Collaborative Filtering
c) Decision Trees
d) Naïve Bayes
Answer: b) Collaborative Filtering (It predicts user preferences based on past
behavior)
18. Which ML technique is used for detecting fake news?
a) NLP + LSTM
b) CNN
c) Decision Trees
d) PCA
Answer: a) NLP + LSTM (LSTMs handle sequential text data effectively)
19. Which evaluation metric is best for imbalanced datasets?
a) Accuracy
b) F1 Score
c) Mean Squared Error
d) Adjusted R²
Answer: b) F1 Score (F1-score balances precision and recall)
20. Which algorithm is best suited for forecasting stock prices?
a) Linear Regression
b) RNN/LSTM
c) Decision Trees
d) K-Means
Answer: b) RNN/LSTM (Time-series forecasting requires memory of past
values)

Miscellaneous & Theoretical Concepts

21. What does a confusion matrix NOT provide?


a) Precision
b) Recall
c) Feature Importance
d) F1 Score
Answer: c) Feature Importance (Confusion matrix is used for classification
metrics)

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

22. What does Variance in Bias-Variance tradeoff represent?


a) Model underfitting
b) Model overfitting
c) Model complexity
d) Data noise
Answer: b) Model overfitting (High variance means the model fits training data
too closely)

🔥 ML Coding Problems for Interviews

1. Implement Logistic Regression from Scratch

Problem: Implement a logistic regression model without using libraries like sklearn. Use
numpy to compute gradients and optimize the loss function using gradient descent.

Solution Outline:

• Define the sigmoid function


• Compute cost using binary cross-entropy
• Implement gradient descent updates

import numpy as np

class LogisticRegression:
def __init__(self, learning_rate=0.01, epochs=1000):
[Link] = learning_rate
[Link] = epochs
[Link] = None
[Link] = None

def sigmoid(self, z):


return 1 / (1 + [Link](-z))

def fit(self, X, y):


n_samples, n_features = [Link]
[Link] = [Link](n_features)
[Link] = 0

for _ in range([Link]):
linear_model = [Link](X, [Link]) + [Link]
predictions = [Link](linear_model)

dw = (1 / n_samples) * [Link](X.T, (predictions - y))


db = (1 / n_samples) * [Link](predictions - y)

[Link] -= [Link] * dw
[Link] -= [Link] * db

def predict(self, X):


linear_model = [Link](X, [Link]) + [Link]
return [Link](linear_model) >= 0.5

2. Build a Decision Tree from Scratch

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

Problem: Implement a Decision Tree algorithm (ID3 or CART) using recursion and entropy
for splitting.

Solution Outline:

• Calculate entropy and information gain


• Split data based on the best attribute
• Recursively build a tree

3. Implement K-Means Clustering Algorithm

Problem: Implement K-Means clustering from scratch in Python.

Solution Outline:

• Initialize K random centroids


• Assign data points to nearest centroid
• Compute new centroids until convergence

4. Implement a Neural Network from Scratch

Problem: Implement a simple 2-layer neural network for binary classification using
NumPy.

Solution Outline:

• Use forward and backward propagation


• Train with gradient descent

5. Hyperparameter Tuning using GridSearchCV

Problem: Optimize a RandomForestClassifier model on a dataset using GridSearchCV.

from sklearn.model_selection import GridSearchCV


from [Link] import RandomForestClassifier

params = {
'n_estimators': [10, 50, 100],
'max_depth': [None, 10, 20],
'min_samples_split': [2, 5, 10]
}

grid = GridSearchCV(RandomForestClassifier(), param_grid=params, cv=5)


[Link](X_train, y_train)

print(grid.best_params_)

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

Scenario-Based ML Interview Questions

These questions test your problem-solving skills, debugging ability, and experience
handling real-world ML problems.

📌 6. Handling Data Imbalance in a Fraud Detection System

Scenario: You’re working on a fraud detection model where fraudulent transactions make
up only 2% of the dataset. Your accuracy is 98%, but it fails to detect frauds. What should
you do?

Solution Approaches:

• Use Precision-Recall over Accuracy


• Apply SMOTE (Synthetic Minority Oversampling Technique)
• Use Anomaly Detection models like Autoencoders

📌 7. Your Model is Overfitting, What Would You Do?

Scenario: You built a deep learning model with high accuracy on training data but poor
test performance. How do you fix this?

Solution Approaches:

• Use Dropout to prevent overfitting


• Add L1/L2 regularization
• Reduce model complexity (prune unnecessary layers)
• Get more training data (data augmentation)

📌 8. Choosing the Right Algorithm for Image Classification

Scenario: You need to build an image classification model with high accuracy and low
inference time. Which model should you choose and why?

Solution:

• For high accuracy: ResNet, EfficientNet


• For low inference time: MobileNet, SqueezeNet

📌 9. Feature Engineering for Time-Series Forecasting

Scenario: You are forecasting sales data. What are the best features to extract?

Feature Engineering Steps:

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

• Extract seasonality trends


• Use moving averages, exponential smoothing
• Create lag features (previous week’s sales as input)

📌 10. Scaling ML Models for Large Datasets

Scenario: You have a dataset with 500 million rows. Your ML model training is very slow.
What do you do?

Optimization Techniques:

• Use Dask/Spark for distributed computing


• Train using mini-batches (batch gradient descent)
• Reduce dimensionality with PCA

📌 11. Model Deployment - What Tools to Use?

Scenario: You have trained an ML model and now need to deploy it as an API. What
technologies do you use?

Deployment Stack:

• FastAPI or Flask for serving


• Docker + Kubernetes for scaling
• TensorFlow Serving for deep learning models

📌 12. Concept Drift in ML Models

Scenario: Your ML model's accuracy decreases over time. What could be the reason?

Possible Causes:

• Concept Drift: Data distribution changes over time


• Feature Drift: Important features lose relevance
• Solution: Periodically retrain the model

📌 13. Explain Why PCA is Used Before Training a Model

Scenario: You have a dataset with 500+ features. Why should you use PCA before
training?

Reasons to Use PCA:

• Removes noise and redundancy


• Reduces computational cost

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

• Improves model performance

📌 14. How to Handle Categorical Data in ML Models?

Scenario: You have categorical data in your dataset. How do you preprocess it?

Encoding Methods:

• Label Encoding (for ordinal categories)


• One-Hot Encoding (for non-ordinal categories)
• Embedding Layers (for deep learning)

📌 15. Handling Missing Data in a Predictive Model

Scenario: You have missing values in your dataset. How do you handle them?

Approaches:

• Drop missing rows (if data loss is small)


• Impute missing values (mean, median, mode)
• Use KNN or regression-based imputation

🔥 Advanced ML Coding Problems for Interviews

16. Implement Support Vector Machine (SVM) from Scratch

Problem: Implement a linear SVM classifier using the hinge loss function and gradient
descent.

Solution Outline:

• Use Hinge loss: L=max⁡(0,1−y(wx+b))L = \max(0, 1 - y(wx +


b))L=max(0,1−y(wx+b))
• Optimize with Stochastic Gradient Descent (SGD)

17. Implement K-Nearest Neighbors (KNN) from Scratch

Problem: Write a KNN classifier without using sklearn.

Solution Outline:

• Compute Euclidean distance between test and train samples


• Find k nearest neighbors
• Predict class based on majority vote

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

18. Implement Principal Component Analysis (PCA)

Problem: Implement PCA to reduce dimensionality of a dataset.

Solution Outline:

• Compute covariance matrix


• Find eigenvectors & eigenvalues
• Transform data into new basis

19. Implement XGBoost from Scratch (Gradient Boosting)

Problem: Implement a basic gradient boosting decision tree (XGBoost) in Python.

Solution Outline:

• Build weak learners (decision trees)


• Compute gradient of loss function
• Update weights using learning rate

20. Implement an Autoencoder for Anomaly Detection

Problem: Train an Autoencoder to detect anomalies in time-series data.

Solution Outline:

• Use a simple feedforward neural network


• Train to reconstruct normal data
• Detect anomalies when reconstruction error is high

21. Train a GAN for Image Generation

Problem: Train a Generative Adversarial Network (GAN) to generate new images.

Solution Outline:

• Implement Generator and Discriminator networks


• Use Binary Cross-Entropy loss
• Train using Minimax game approach

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

22. Implement Reinforcement Learning (Q-Learning) for a Grid World

Problem: Implement Q-Learning for an agent to learn the best path in a grid.

Solution Outline:

• Use Q-table to store state-action values


• Apply Bellman Equation
• Use ε-greedy exploration

23. Implement CNN for Image Classification without TensorFlow/Keras

Problem: Build a Convolutional Neural Network (CNN) from scratch using only NumPy.

Solution Outline:

• Implement Convolution & Pooling layers


• Train with Backpropagation

24. Detect Outliers Using Isolation Forest

Problem: Use Isolation Forest to detect anomalies in a dataset.

from [Link] import IsolationForest

model = IsolationForest(contamination=0.05)
outliers = model.fit_predict(X)

print(outliers)

25. Implement LSTM for Stock Price Prediction

Problem: Train an LSTM model to predict stock prices using past data.

Solution Outline:

• Prepare time-series sequences


• Use LSTM layers in Keras
• Train with Mean Squared Error (MSE)

🔥 Scenario-Based ML Interview Questions

26. Model Deployment – Batch vs Real-Time Inference

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

Scenario: You are deploying an ML model. Should you use batch inference or real-time
inference?

Answer:

• Use Batch Processing for offline tasks (e.g., fraud detection).


• Use Real-time APIs for low-latency applications (e.g., chatbots).

27. Why Do We Use Dropout in Neural Networks?

Scenario: Your deep learning model overfits. How does Dropout help?

Answer:

• Dropout randomly disables neurons during training.


• This forces the model to learn robust features.

28. What Happens if Your Dataset Has Collinear Features?

Scenario: Your dataset has highly correlated features. What’s the best way to handle it?

Answer:

• Use VIF (Variance Inflation Factor) to remove redundant features.


• Apply Principal Component Analysis (PCA).

29. What’s the Difference Between Bagging and Boosting?

Scenario: You need to choose between Random Forest (Bagging) and XGBoost
(Boosting). Which one do you pick?

Answer:

• Bagging (e.g., Random Forest) reduces variance, useful for high bias models.
• Boosting (e.g., XGBoost) reduces bias, better for complex problems.

30. How to Handle Concept Drift in Production ML Models?

Scenario: Your ML model’s accuracy drops over time due to changing data. What do you
do?

By Prof. Ameya Saonerkar, RBU.


MCQ ML Interview Preparation

Solution Approaches:

• Periodically retrain the model with fresh data.


• Use drift detection algorithms (e.g., ADWIN).
• Implement continual learning.

By Prof. Ameya Saonerkar, RBU.

You might also like