AI & Machine Learning Topic
AI & Machine Learning Interview Questions
Fundamental Concepts
1. What is the difference between Artificial Intelligence, Machine Learning, and Deep Learning?
Answer:
-
Artificial Intelligence (AI): Broad field of creating intelligent machines that can simulate human thinking and behavior.
-
Machine Learning (ML): Subset of AI that uses algorithms to learn patterns from data without being explicitly programmed.
-
Deep Learning (DL): Subset of ML that uses neural networks with many layers to learn complex patterns from large amounts of data.
Analogy: AI is the goal of creating intelligent machines, ML is the approach to achieve it, and DL is a powerful technique within ML.
2. What are the main types of Machine Learning? Explain each.
Answer:
-
Supervised Learning: Model learns from labeled data (input-output pairs). Used for prediction and classification.
-
Examples: Spam detection, house price prediction
-
-
Unsupervised Learning: Model finds patterns in unlabeled data. Used for clustering and association.
-
Examples: Customer segmentation, anomaly detection
-
-
Reinforcement Learning: Model learns through trial and error using rewards and punishments.
-
Examples: Game playing AI, robotics
-
3. What is the difference between Classification and Regression?
Answer:
-
Classification: Predicts discrete/categorical outcomes (classes/labels).
-
Examples: Spam/Not spam, Dog/Cat, Positive/Negative sentiment
-
-
Regression: Predicts continuous numerical values.
-
Examples: House prices, Temperature, Stock prices
-
4. What is Overfitting and Underfitting? How do you prevent them?
Answer:
-
Overfitting: Model learns training data too well, including noise, and performs poorly on new data. (High variance)
-
Underfitting: Model fails to capture underlying patterns in data. (High bias)
Prevention:
-
For Overfitting:
-
Cross-validation
-
Regularization (L1/L2)
-
Early stopping
-
Reduce model complexity
-
Get more training data
-
-
For Underfitting:
-
Increase model complexity
-
Add more features
-
Reduce regularization
-
Train for longer
-
5. What is Cross-Validation and why is it important?
Answer: Cross-validation is a technique to evaluate model performance by splitting data into multiple folds.
Common approach - k-Fold Cross Validation:
-
Split data into k equal parts
-
Use k-1 parts for training, 1 part for testing
-
Repeat k times, using each fold as test set once
-
Average the results
Importance:
-
More reliable performance estimate
-
Better use of limited data
-
Reduces overfitting risk
Technical Concepts
6. What is the Bias-Variance Tradeoff?
Answer:
-
Bias: Error from overly simplistic assumptions. High bias causes underfitting.
-
Variance: Error from sensitivity to small fluctuations in training data. High variance causes overfitting.
Tradeoff: As model complexity increases:
-
Bias decreases
-
Variance increases
The goal is to find the right balance.
7. Explain the Confusion Matrix and its metrics.
Answer: A table showing model performance on classification problems.
text
Predicted: No Predicted: Yes
Actual: No True Negative False Positive
Actual: Yes False Negative True Positive
Key Metrics:
-
Accuracy: (TP + TN) / Total
-
Precision: TP / (TP + FP) - How accurate positive predictions are
-
Recall/Sensitivity: TP / (TP + FN) - How well we find actual positives
-
F1-Score: Harmonic mean of precision and recall
8. What is the difference between L1 and L2 Regularization?
Answer:
-
L1 Regularization (Lasso): Adds absolute value of coefficients to loss function. Can shrink coefficients to exactly zero (feature selection).
-
L2 Regularization (Ridge): Adds squared value of coefficients to loss function. Shrinks coefficients but rarely to zero.
When to use:
-
L1: When you suspect many irrelevant features
-
L2: When all features might be relevant
9. What is Gradient Descent and how does it work?
Answer: Optimization algorithm used to minimize the loss function by iteratively moving towards the minimum.
Process:
-
Initialize parameters randomly
-
Calculate gradient (derivative) of loss function
-
Update parameters:
θ = θ - learning_rate * gradient -
Repeat until convergence
Types:
-
Batch GD: Uses entire dataset for each update
-
Stochastic GD: Uses one sample per update
-
Mini-batch GD: Uses small batches of data
10. What is the difference between Bagging and Boosting?
Answer:
-
Bagging (Bootstrap Aggregating):
-
Trains multiple models independently on random subsets of data
-
Reduces variance
-
Example: Random Forest
-
Models run in parallel
-
-
Boosting:
-
Trains models sequentially, each correcting the previous one
-
Reduces bias
-
Examples: AdaBoost, Gradient Boosting, XGBoost
-
Models run sequentially
-
Practical Implementation
11. How do you handle missing values in a dataset?
Answer:
-
Numerical data:
-
Mean/Median imputation
-
Regression imputation
-
K-NN imputation
-
-
Categorical data:
-
Mode imputation
-
Create "Missing" category
-
-
Other approaches:
-
Delete rows/columns (if small percentage missing)
-
Use algorithms that handle missing values (like XGBoost)
-
12. What is Feature Engineering and why is it important?
Answer: Process of creating new features or transforming existing ones to improve model performance.
Common techniques:
-
Encoding: One-hot encoding, label encoding
-
Scaling: Standardization, Normalization
-
Creation: Polynomial features, interaction terms
-
Transformation: Log transform, binning
Importance: Better features often beat better algorithms. Good features can make simple models perform exceptionally well.
13. What is One-Hot Encoding and when do you use it?
Answer: Technique to convert categorical variables into binary (0/1) columns.
Example: Colors: Red, Green, Blue becomes:
-
Red: [1, 0, 0]
-
Green: [0, 1, 0]
-
Blue: [0, 0, 1]
When to use:
-
For nominal categorical data (no order)
-
When categories have no inherent ranking
-
Before feeding to algorithms that expect numerical input
14. Explain Train-Test Split and why it's used.
Answer: Splitting dataset into two parts:
-
Training set: Used to train the model (typically 70-80%)
-
Testing set: Used to evaluate final model performance (typically 20-30%)
Why important:
-
Evaluates how well model generalizes to unseen data
-
Prevents overfitting
-
Provides realistic performance estimate
python
from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
15. What is the purpose of Activation Functions in Neural Networks?
Answer: Activation functions introduce non-linearity into the network, allowing it to learn complex patterns.
Common activation functions:
-
Sigmoid: Output between 0-1, used for binary classification
-
Tanh: Output between -1 to 1, zero-centered
-
ReLU: Most popular, solves vanishing gradient problem
-
Softmax: Used in output layer for multi-class classification
Advanced Concepts
16. What is Transfer Learning and when would you use it?
Answer: Using a pre-trained model on a new related task.
Process:
-
Take model trained on large dataset (e.g., ImageNet)
-
Remove final layers
-
Add new layers for your specific task
-
Fine-tune on your smaller dataset
When to use:
-
Limited labeled data
-
Limited computational resources
-
Similar domain to pre-trained model
17. What are Convolutional Neural Networks (CNNs) and where are they used?
Answer: Specialized neural networks for processing grid-like data (images, videos).
Key components:
-
Convolutional layers: Extract features using filters
-
Pooling layers: Reduce dimensionality
-
Fully connected layers: Final classification
Applications:
-
Image classification
-
Object detection
-
Medical imaging
-
Self-driving cars
18. What is Natural Language Processing (NLP) and common techniques?
Answer: Field focused on interaction between computers and human language.
Common techniques:
-
Tokenization: Splitting text into words/tokens
-
TF-IDF: Term frequency-inverse document frequency
-
Word Embeddings: Word2Vec, GloVe, FastText
-
Transformers: BERT, GPT (state-of-the-art)
19. What is the difference between Supervised and Unsupervised Learning in practice?
Answer:
| Aspect | Supervised | Unsupervised |
|---|---|---|
| Data | Labeled | Unlabeled |
| Goal | Predict outcomes | Find patterns |
| Feedback | Direct (labels) | Indirect (patterns) |
| Examples | Classification, Regression | Clustering, Dimensionality Reduction |
| Evaluation | Clear metrics (accuracy, etc.) | Subjective (silhouette score, etc.) |
20. How would you approach a new Machine Learning problem?
Answer: Systematic approach:
-
Problem Understanding:
-
Define business objective
-
Identify success metrics
-
-
Data Collection & Exploration:
-
Gather relevant data
-
Exploratory Data Analysis (EDA)
-
-
Data Preprocessing:
-
Handle missing values
-
Feature engineering
-
Data splitting
-
-
Model Selection & Training:
-
Start with simple baselines
-
Try multiple algorithms
-
Hyperparameter tuning
-
-
Evaluation & Deployment:
-
Evaluate on test set
-
Deploy model
-
Monitor performance
-
Bonus: Scenario-Based Questions
21. How would you explain a complex ML model to a non-technical stakeholder?
Answer:
-
Use analogies and simple language
-
Focus on business impact, not technical details
-
Show concrete examples of predictions
-
Explain in terms of risk, cost, or benefit
-
Use visualizations when possible
22. What metrics would you use for an imbalanced classification problem?
Answer: Accuracy is misleading for imbalanced data. Better metrics:
-
Precision-Recall curve
-
F1-Score
-
AUC-ROC curve
-
Cohen's Kappa
-
Confusion matrix analysis
These questions cover the fundamental knowledge expected from freshers in AI/ML interviews. Focus on understanding the concepts deeply rather than just memorizing answers!
Comments (0)
No comments yet. Be the first to comment!