1What is Artificial Intelligence?
Artificial Intelligence (AI) is the simulation of human intelligence processes by computer systems. The term was coined in 1956 by John McCarthy at the Dartmouth Conference, but the ideas behind it stretch back to Alan Turing's foundational 1950 paper "Computing Machinery and Intelligence," where he asked the famous question: "Can machines think?"
At its core, AI refers to machines that can perform tasks that would normally require human intelligence — things like understanding natural language, recognising faces, playing chess, diagnosing diseases, or driving a car. The key insight is that "intelligence" is not magic — it is pattern recognition, reasoning, and decision-making under uncertainty — all of which can be approximated computationally.
Types of AI by Capability
🐣 Narrow AI (ANI)
Designed for one specific task. All current commercial AI falls here — ChatGPT, Google Search, Siri, Alexa, recommendation engines.
🧠 General AI (AGI)
Hypothetical AI with human-level reasoning across all domains — can learn any intellectual task a human can. Debated among researchers.
🚀 Superintelligent AI (ASI)
AI that surpasses human intelligence in every domain. Subject of both excitement and existential concern in AI safety research.
Types of AI by Functionality
| Type | Description | Example | Learns? |
|---|---|---|---|
| Reactive Machines | No memory, reacts only to current input | Deep Blue (Chess) | No |
| Limited Memory | Uses past data for decisions | Self-driving cars, ChatGPT | Yes |
| Theory of Mind | Understands emotions, beliefs of others | Research stage only | Partially |
| Self-Aware AI | Has consciousness, self-understanding | Does not exist yet | Unknown |
AI vs ML vs Deep Learning — The Real Difference
These three terms are often used interchangeably but they are not the same thing. Think of them as nested circles:
- AI = The broad goal of making machines smart (includes rule-based systems, search algorithms, ML, DL)
- Machine Learning = A method of achieving AI where systems learn from data automatically
- Deep Learning = A type of ML using multi-layer neural networks, particularly powerful for images, text, and audio
Real-World Applications of AI in 2026
- Healthcare: Disease diagnosis from X-rays, drug discovery, patient risk scoring, robotic surgery assistance
- Finance: Fraud detection, algorithmic trading, credit scoring, customer service chatbots
- Education: Personalised learning paths, automated grading, plagiarism detection, doubt-solving bots
- Transportation: Route optimisation, self-driving vehicles, predictive maintenance of engines
- Agriculture: Crop yield prediction, soil analysis, pest detection from drone footage
- Retail: Product recommendation, demand forecasting, visual search, checkout-free stores
- Security: Intrusion detection, facial recognition, malware classification (like LSGP Antivirus)
2History and Evolution of AI
Understanding where AI came from gives you critical context for why it works the way it does today, and why certain techniques exist. The field did not progress in a straight line — it had two major "winters" where funding dried up due to overpromising and underdelivering.
| Era | Key Milestone | Why It Matters |
|---|---|---|
| 1950 | Turing Test proposed by Alan Turing | First formal definition of machine intelligence |
| 1956 | Dartmouth Conference — AI named as a field | McCarthy, Minsky, Shannon gathered to define AI |
| 1958 | Perceptron invented by Rosenblatt | First artificial neural network — foundation of DL |
| 1966–74 | First AI Winter | NLP machines failed; funding cut; optimism crashed |
| 1980s | Expert Systems rise | Rule-based AI for medical/business diagnosis |
| 1987–93 | Second AI Winter | Expert systems too rigid; LISP machines failed |
| 1997 | Deep Blue beats Kasparov at chess | Proved AI can beat world champions in bounded domains |
| 2006 | Hinton's Deep Belief Networks paper | Deep learning became viable again |
| 2012 | AlexNet wins ImageNet by huge margin | Deep learning's public breakthrough — CNN revolution begins |
| 2016 | AlphaGo beats Lee Sedol at Go | Reinforcement learning milestone; Go has more positions than atoms in universe |
| 2017 | Transformer architecture published (Attention Is All You Need) | Foundation of GPT, BERT, all modern LLMs |
| 2022-26 | ChatGPT, Gemini, Claude, GPT-4o, Sora | Generative AI enters mainstream; multimodal systems become common |
3Machine Learning — Core Concepts
Machine Learning is a method of data analysis that automates analytical model building. It is based on the idea that systems can learn from data, identify patterns, and make decisions with minimal human intervention. Unlike traditional programming where you give the computer explicit rules, in ML you give the computer data and let it find the rules itself.
The Three Learning Paradigms
| Type | Input Data | Goal | Examples |
|---|---|---|---|
| Supervised Learning | Labelled (X, y pairs) | Learn a mapping from X → y | Spam detection, house price prediction, image classification |
| Unsupervised Learning | Unlabelled (X only) | Find hidden structure in data | Customer segmentation, anomaly detection, topic modelling |
| Reinforcement Learning | States, Actions, Rewards | Maximise cumulative reward over time | Game playing (AlphaGo), robot control, recommendation tuning |
| Semi-Supervised | Small labelled + large unlabelled | Combine both to improve learning | Image classification with few labelled examples |
| Self-Supervised | Data creates its own labels | Pre-train representations | GPT (predict next word), BERT (mask language modelling) |
Key ML Terminology — Know These Cold for Interviews
- Feature (X): An input variable used to make predictions. E.g., house size, location, age
- Label (y): The output variable we are trying to predict. E.g., house price
- Training set: Data used to train the model (typically 70-80% of your data)
- Validation set: Data used to tune hyperparameters during training (typically 10-15%)
- Test set: Data held out to evaluate final model performance (never seen during training)
- Overfitting: Model performs well on training data but poorly on new data — it memorised rather than learnt
- Underfitting: Model is too simple to capture the pattern — performs poorly on both training and test data
- Bias-Variance Tradeoff: High bias = underfitting; High variance = overfitting. The goal is the sweet spot in between
- Hyperparameter: A parameter set before training (e.g., learning rate, number of trees) — not learnt from data
- Epoch: One full pass through the training dataset during model training
- Batch size: Number of training samples processed before model weights are updated
How a Model Learns — Gradient Descent Explained Simply
Most ML algorithms learn by minimising a loss function — a measure of how wrong the model's predictions are. Gradient descent is the algorithm that performs this minimisation:
- Initialise: Start with random model weights (parameters)
- Forward pass: Make predictions using current weights
- Calculate loss: Measure how wrong the predictions are (e.g., Mean Squared Error)
- Backpropagation: Calculate the gradient (direction of steepest increase) of the loss
- Update weights: Move weights in the opposite direction of the gradient, scaled by the learning rate
- Repeat: Continue until the loss stops decreasing (convergence)
Where: w = weights, α = learning rate, ∂L/∂w = gradient of loss with respect to weights
4Supervised Learning — Algorithms with Python Code
Supervised learning is the most widely used paradigm in practical ML. You have a labelled dataset and you want to learn a function that maps inputs to outputs. There are two main tasks: regression (predict a continuous value) and classification (predict a discrete category).
4.1 Linear Regression
Linear regression assumes the relationship between input X and output y is a straight line. It finds the best-fit line through your data by minimising the sum of squared errors. Despite its simplicity, it is extremely powerful when the assumption holds and is the foundation of many advanced models.
Where: β₀ = intercept, β₁...βₙ = coefficients (learnt from data), ε = error term
# Linear Regression: Predict house price from size import numpy as np import pandas as pd from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split from sklearn.metrics import mean_squared_error, r2_score import matplotlib.pyplot as plt # ─── 1. Create sample dataset ─── np.random.seed(42) house_size = np.random.randint(500, 3500, 100) # sq ft price = house_size * 150 + np.random.normal(0, 20000, 100) # in Rs X = house_size.reshape(-1, 1) # Reshape for sklearn (n_samples, n_features) y = price # ─── 2. Split data 80/20 ─── X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.2, random_state=42 ) print(f"Training samples: {len(X_train)}, Test samples: {len(X_test)}") # ─── 3. Train the model ─── model = LinearRegression() model.fit(X_train, y_train) # ─── 4. View learnt parameters ─── print(f"Intercept (β₀): {model.intercept_:.2f}") print(f"Coefficient (β₁): {model.coef_[0]:.2f}") # Output: Intercept ≈ 1200, Coefficient ≈ 150 (close to our true values!) # ─── 5. Make predictions ─── y_pred = model.predict(X_test) # ─── 6. Evaluate ─── mse = mean_squared_error(y_test, y_pred) rmse = np.sqrt(mse) r2 = r2_score(y_test, y_pred) print(f"RMSE: {rmse:.2f}") # Root Mean Squared Error (in same units as y) print(f"R² Score: {r2:.4f}") # 1.0 = perfect, 0 = as good as mean baseline # ─── 7. Predict for a new house ─── new_house = np.array([[1800]]) # 1800 sq ft predicted_price = model.predict(new_house)[0] print(f"Predicted price for 1800 sq ft: ₹{predicted_price:,.0f}")
Evaluation Metrics for Regression
| Metric | Formula | Interpretation | Range |
|---|---|---|---|
| MAE | mean(|y - ŷ|) | Average absolute error; easy to interpret | 0 to ∞, lower is better |
| MSE | mean((y - ŷ)²) | Penalises large errors more; differentiable | 0 to ∞, lower is better |
| RMSE | √MSE | Same units as y; most commonly reported | 0 to ∞, lower is better |
| R² Score | 1 - SS_res/SS_tot | Proportion of variance explained by model | -∞ to 1, higher is better |
4.2 Logistic Regression (Classification)
Despite the name, Logistic Regression is a classification algorithm, not regression. It models the probability that an input belongs to a particular class, using the sigmoid function to squish any input to the range (0, 1).
from sklearn.linear_model import LogisticRegression from sklearn.datasets import make_classification from sklearn.metrics import classification_report, confusion_matrix from sklearn.preprocessing import StandardScaler # Simulate email spam dataset (binary classification) X, y = make_classification( n_samples=1000, n_features=20, n_informative=10, random_state=42 ) # y = 0 (not spam) or 1 (spam) # Split and scale (IMPORTANT: scale features for logistic regression) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) scaler = StandardScaler() X_train = scaler.fit_transform(X_train) # fit on train only! X_test = scaler.transform(X_test) # transform test with same scaler # Train clf = LogisticRegression(max_iter=200, random_state=42) clf.fit(X_train, y_train) # Evaluate y_pred = clf.predict(X_test) print(classification_report(y_test, y_pred, target_names=['Not Spam', 'Spam'])) print("Confusion Matrix:") print(confusion_matrix(y_test, y_pred)) # Get probability (not just class) for a single email email_features = X_test[0].reshape(1, -1) prob = clf.predict_proba(email_features)[0] print(f"P(Not Spam) = {prob[0]:.3f}, P(Spam) = {prob[1]:.3f}")
4.3 Decision Trees and Random Forests
Decision Trees split data based on feature thresholds, forming a tree of if-else rules. They are highly interpretable. Random Forests combine hundreds of decision trees, each trained on a random subset of data and features, then vote on the final prediction — this is called ensemble learning.
from sklearn.ensemble import RandomForestClassifier from sklearn.datasets import load_iris # Classic iris flower classification dataset iris = load_iris() X, y = iris.data, iris.target # Features: sepal length, sepal width, petal length, petal width # Classes: 0=setosa, 1=versicolor, 2=virginica X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42) rf = RandomForestClassifier( n_estimators=100, # 100 trees max_depth=5, # limit depth to avoid overfitting random_state=42 ) rf.fit(X_train, y_train) print(f"Accuracy: {rf.score(X_test, y_test):.4f}") # Feature importance — which features matter most? importances = rf.feature_importances_ for name, imp in zip(iris.feature_names, importances): print(f" {name}: {imp:.4f}") # Petal length and petal width will be most important (~0.85 combined)
Classification Metrics — Know the Difference
| Metric | Formula | When to Use |
|---|---|---|
| Accuracy | (TP+TN) / Total | Balanced classes; avoid with imbalanced data |
| Precision | TP / (TP+FP) | When false positives are costly (spam filter — don't block real email) |
| Recall | TP / (TP+FN) | When false negatives are costly (cancer detection — don't miss sick patients) |
| F1 Score | 2 × (P×R)/(P+R) | Balance of precision and recall; good for imbalanced classes |
| ROC-AUC | Area under ROC curve | Overall discriminative power across all thresholds |
5Unsupervised Learning — Patterns Without Labels
Unsupervised learning works on data without labels. The goal is to discover hidden structure — groupings, patterns, or compressed representations — entirely from the data itself. It is used when labelling data is expensive, impossible, or when you do not know what to look for in advance.
5.1 K-Means Clustering
K-Means is the most popular clustering algorithm. It partitions data into K clusters where each data point belongs to the cluster with the nearest centroid (mean). The algorithm alternates between assigning points to clusters and updating centroids until convergence.
from sklearn.cluster import KMeans from sklearn.datasets import make_blobs from sklearn.metrics import silhouette_score import numpy as np # Generate synthetic customer data (age vs spending score) X, _ = make_blobs(n_samples=300, centers=4, cluster_std=0.8, random_state=42) # ─── Elbow Method: Find optimal K ─── inertias = [] k_range = range(1, 11) for k in k_range: km = KMeans(n_clusters=k, random_state=42, n_init=10) km.fit(X) inertias.append(km.inertia_) # Plot inertia vs K — look for the "elbow" where it stops dropping sharply # ─── Train with K=4 (the elbow) ─── kmeans = KMeans(n_clusters=4, random_state=42, n_init=10) labels = kmeans.fit_predict(X) # Evaluate clustering quality sil_score = silhouette_score(X, labels) print(f"Silhouette Score: {sil_score:.4f}") # Range: -1 (bad) to 1 (perfect). Above 0.5 is generally good. # Cluster centers print("Cluster Centers:") print(kmeans.cluster_centers_) # Assign new customer to a cluster new_customer = np.array([[3.5, 2.1]]) cluster = kmeans.predict(new_customer)[0] print(f"New customer belongs to cluster: {cluster}")
5.2 Principal Component Analysis (PCA)
PCA is a dimensionality reduction technique that finds the directions of maximum variance in high-dimensional data and projects data onto these directions (called principal components). It reduces the number of features while retaining most of the information, making models faster and visualisation possible.
from sklearn.decomposition import PCA from sklearn.preprocessing import StandardScaler from sklearn.datasets import load_breast_cancer # Breast cancer dataset: 30 features → reduce to 2 for visualisation data = load_breast_cancer() X, y = data.data, data.target print(f"Original shape: {X.shape}") # (569, 30) # Always scale before PCA (PCA is sensitive to scale) scaler = StandardScaler() X_scaled = scaler.fit_transform(X) # Reduce to 2 components for 2D plot pca = PCA(n_components=2) X_pca = pca.fit_transform(X_scaled) print(f"Reduced shape: {X_pca.shape}") # (569, 2) # How much variance do the 2 components explain? print(f"Variance explained: {pca.explained_variance_ratio_.sum():.2%}") # Typically ~63% for this dataset — 63% of info in just 2 dimensions! # Find how many components needed for 95% variance pca_full = PCA(n_components=0.95) # keep 95% variance X_full_pca = pca_full.fit_transform(X_scaled) print(f"Components for 95% variance: {pca_full.n_components_}") # ~10
6Deep Learning & Neural Networks
Deep Learning is a subset of Machine Learning that uses artificial neural networks with many layers (hence "deep") to learn representations of data at progressively higher levels of abstraction. It powers almost every AI breakthrough in the last 10 years — image recognition, language models, text-to-speech, generative AI, and more.
How a Neural Network Works
A neural network consists of layers of interconnected nodes (neurons). Each connection has a weight. Data flows forward through the network (forward pass), and errors are propagated backward (backpropagation) to update weights. This cycle repeats for thousands or millions of iterations.
- Input Layer: Receives the raw features (one node per feature)
- Hidden Layers: Apply transformations through weights and activation functions; extract patterns
- Output Layer: Produces the final prediction (single node for regression; one per class for classification)
- Activation Functions: Non-linear transformations applied at each neuron (ReLU, Sigmoid, Tanh, Softmax)
Key Activation Functions
| Function | Formula | Range | Best Used | Weakness |
|---|---|---|---|---|
| Sigmoid | 1/(1+e⁻ˣ) | (0, 1) | Binary output layer | Vanishing gradient |
| Tanh | (eˣ-e⁻ˣ)/(eˣ+e⁻ˣ) | (-1, 1) | Hidden layers (older) | Vanishing gradient |
| ReLU | max(0, x) | [0, ∞) | Hidden layers (default choice) | Dying ReLU |
| Leaky ReLU | max(0.01x, x) | (-∞, ∞) | Fixes dying ReLU | Not adaptive |
| Softmax | eˣⁱ / Σeˣʲ | (0,1) sums to 1 | Multi-class output | Computationally heavy |
import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers import numpy as np # Load MNIST digit recognition (28x28 greyscale images, digits 0-9) (X_train, y_train), (X_test, y_test) = keras.datasets.mnist.load_data() # Preprocess: normalize to [0,1] and flatten 28x28 → 784 X_train = X_train.reshape(-1, 784) / 255.0 X_test = X_test.reshape(-1, 784) / 255.0 # ─── Build the model ─── model = keras.Sequential([ layers.Dense(256, activation='relu', input_shape=(784,)), layers.Dropout(0.3), # Randomly drop 30% of neurons to prevent overfitting layers.Dense(128, activation='relu'), layers.Dropout(0.2), layers.Dense(10, activation='softmax') # 10 output classes (digits 0-9) ]) # ─── Compile ─── model.compile( optimizer='adam', # Adaptive learning rate optimiser loss='sparse_categorical_crossentropy', # Multi-class classification loss metrics=['accuracy'] ) model.summary() # ~235,146 trainable parameters # ─── Train ─── history = model.fit( X_train, y_train, epochs=10, batch_size=128, validation_split=0.1, verbose=1 ) # ─── Evaluate on test set ─── test_loss, test_acc = model.evaluate(X_test, y_test) print(f"Test Accuracy: {test_acc:.4f}") # Typically ~97.5-98% # ─── Predict a single image ─── img = X_test[0].reshape(1, 784) probabilities = model.predict(img)[0] predicted_digit = np.argmax(probabilities) print(f"Predicted digit: {predicted_digit} (confidence: {probabilities[predicted_digit]:.2%})")
CNN, RNN, Transformer — When to Use Which
| Architecture | Best For | Key Feature | Famous Examples |
|---|---|---|---|
| CNN (Convolutional Neural Network) |
Images, videos, spatial data | Shared convolutional filters detect local patterns regardless of position | ResNet, VGG, EfficientNet, YOLO |
| RNN/LSTM (Recurrent Neural Network) |
Sequential data, time series, older NLP | Maintains hidden state across sequence; remembers past context | LSTM for speech recognition, seq2seq translation |
| Transformer | NLP, multimodal, everything modern | Self-attention: each token attends to every other token simultaneously | BERT, GPT-4, Claude, Gemini, Sora |
| GAN (Generative Adversarial Network) |
Image generation, data augmentation | Two networks (generator vs discriminator) compete, improving each other | StyleGAN, BigGAN, image-to-image translation |
7Data Science & the Complete ML Pipeline
Data science is the discipline of extracting actionable insight from raw data. In practice, it is 80% data cleaning and preparation, and 20% actual modelling. Every ML project follows a pipeline — skipping any step leads to poor-quality models, no matter how sophisticated the algorithm.
The 7-Step ML Pipeline
Step 1 — Problem Definition
Is this regression or classification? What does success look like? What metric matters? Define this before touching data.
Step 2 — Data Collection
Web scraping, APIs, surveys, sensors, databases. Data quality > data quantity. Garbage in = garbage out.
Step 3 — Exploratory Data Analysis (EDA)
Understand distributions, correlations, outliers, class imbalance. df.describe(), df.info(), heatmaps, boxplots.
Step 4 — Data Preprocessing
Handle missing values, encode categories, scale features, remove outliers, engineer new features.
Step 5 — Model Training & Selection
Try multiple models, use cross-validation, tune hyperparameters with GridSearchCV or Optuna.
Step 6 — Model Evaluation
Evaluate on held-out test set using the right metrics. Check for data leakage. Examine error cases.
Step 7 — Deployment & Monitoring
Serve model via REST API (FastAPI/Flask), monitor for drift, retrain periodically as data changes.
Data Preprocessing — The Most Important Step
import pandas as pd import numpy as np from sklearn.pipeline import Pipeline from sklearn.compose import ColumnTransformer from sklearn.preprocessing import StandardScaler, OneHotEncoder from sklearn.impute import SimpleImputer # Sample messy dataset df = pd.DataFrame({ 'age': [25, np.nan, 35, 28, 45], 'salary': [50000, 60000, np.nan, 75000, 90000], 'city': ['Mumbai', 'Delhi', 'Mumbai', None, 'Bangalore'], 'hired': [1, 0, 1, 1, 0] }) # Define which columns are numeric vs categorical numeric_cols = ['age', 'salary'] cat_cols = ['city'] # Numeric pipeline: impute missing with median, then scale num_pipeline = Pipeline([ ('imputer', SimpleImputer(strategy='median')), ('scaler', StandardScaler()) ]) # Categorical pipeline: impute missing with mode, then one-hot encode cat_pipeline = Pipeline([ ('imputer', SimpleImputer(strategy='most_frequent')), ('encoder', OneHotEncoder(handle_unknown='ignore', sparse_output=False)) ]) # Combine into one preprocessor preprocessor = ColumnTransformer([ ('num', num_pipeline, numeric_cols), ('cat', cat_pipeline, cat_cols) ]) # Prepare features and target X = df.drop('hired', axis=1) y = df['hired'] # Fit and transform X_processed = preprocessor.fit_transform(X) print(f"Processed shape: {X_processed.shape}") # Original: (5, 3) → Processed: (5, 5) [2 scaled numerics + 3 one-hot cities]
8Algorithm Complexity Analysis
Understanding the time and space complexity of ML algorithms is critical for interviews and for choosing the right algorithm in production. A model that takes hours to train or gigabytes of memory is not practical even if its accuracy is high.
Common ML Algorithm Complexities
| Algorithm | Training Time | Prediction Time | Space | Scalability |
|---|---|---|---|---|
| Linear/Logistic Regression | O(n·d) | O(d) | O(d) | Excellent |
| Decision Tree | O(n·d·log n) | O(depth) | O(nodes) | Good |
| Random Forest (k trees) | O(k·n·d·log n) | O(k·depth) | O(k·nodes) | Moderate |
| SVM (kernel) | O(n²·d) to O(n³) | O(n_sv·d) | O(n²) | Poor (large n) |
| KNN (k-nearest) | O(1) [lazy] | O(n·d) | O(n·d) | Poor (large n) |
| K-Means | O(n·K·d·i) | O(K·d) | O(n+K) | Good |
| Neural Network (Dense) | O(e·n·layers·units²) | O(layers·units²) | O(layers·units²) | Good with GPU |
n = samples, d = features, k = trees/clusters, i = iterations, e = epochs, n_sv = support vectors
Bias-Variance Tradeoff — The Central Problem in ML
Bias = How wrong on average is the model's assumption about the data structure?
Variance = How much does model change if trained on different data samples?
| Scenario | Bias | Variance | Symptom | Fix |
|---|---|---|---|---|
| Underfitting | High | Low | Bad on both train and test | More complex model, more features, less regularisation |
| Overfitting | Low | High | Great train, poor test | More data, dropout, regularisation (L1/L2), simpler model |
| Ideal | Low | Low | Good on both | Right model complexity + sufficient data |
9Python Libraries Cheat Sheet
These are the essential libraries you must know for any AI/ML/Data Science role in India. Every data science interview will test your knowledge of at least NumPy, Pandas, and scikit-learn.
a = np.array([1,2,3])
np.zeros((3,3))
np.dot(A, B)
np.reshape(a, (-1,1))
np.mean(a); np.std(a)
a[a > 2] # boolean mask
df = pd.read_csv('data.csv')
df.head(); df.describe()
df['col'].value_counts()
df.dropna(); df.fillna(0)
df.groupby('city').mean()
df.merge(df2, on='id')
model.fit(X_train, y_train)
model.predict(X_test)
model.score(X_test, y_test)
cross_val_score(model, X, y)
GridSearchCV(model, params)
Pipeline([steps...])
model = keras.Sequential([...])
model.compile(loss=..., opt=...)
model.fit(X, y, epochs=10)
model.evaluate(X_test, y_test)
model.save('model.h5')
tf.keras.models.load_model(...)
plt.plot(x, y)
plt.scatter(x, y, c=labels)
plt.hist(data, bins=30)
plt.xlabel('X'); plt.ylabel('Y')
plt.title('My Plot')
plt.savefig('plot.png')
sns.heatmap(df.corr())
sns.boxplot(x='col', data=df)
sns.pairplot(df)
sns.histplot(df['col'])
sns.countplot(x='target', data=df)
🎯 Practice Problems
Click any problem to reveal a hint. Solve these before your next interview — they cover the most asked AI/ML problem types.
🧠 Interactive Quiz — Test Yourself
10 questions covering AI, ML, and Data Science concepts. Click an option to see if you're right. Track your score at the end.
Q1. Which type of machine learning does NOT require labelled training data?
Q2. Your model has 99% training accuracy but 60% test accuracy. What is happening?
Q3. Which activation function is most commonly used in hidden layers of modern deep neural networks?
Q4. In the K-Means algorithm, what does the "elbow method" help you determine?
Q5. Which metric should you prioritise for a cancer diagnosis model where missing a sick patient is very costly?
Q6. What is the purpose of Dropout in a neural network?
Q7. What is the Transformer architecture's key innovation over RNNs?
Q8. Which of the following is NOT a valid technique to handle class imbalance?
Q9. What does R² (R-squared) score of 0.0 mean in regression?
Q10. You should NEVER use your test set for which of the following?
💼 Interview Questions & Answers
Most asked AI/ML questions at TCS, Infosys, Wipro, Accenture, Amazon, Flipkart, and startups. Click to expand.
A hyperparameter is set by the user before training begins and controls the learning process itself — for example, the learning rate, number of layers, number of trees, regularisation strength (C in SVM), or batch size. Hyperparameters are tuned using techniques like GridSearchCV, RandomizedSearchCV, or Bayesian optimisation on the validation set.
Stochastic Gradient Descent (SGD): Updates weights after every single sample. Fast and noisy — the noise can actually help escape local minima but makes convergence erratic.
Mini-batch GD: Updates after a batch of samples (e.g., 32, 64, 128). Best of both worlds — faster than batch GD, smoother than SGD. This is what Keras/PyTorch use by default.
Adam: Adaptive Moment Estimation. Combines momentum (remembers past gradients) with adaptive learning rates per parameter. Currently the most popular optimiser. Works well with default settings (lr=0.001, β1=0.9, β2=0.999).
L2 Regularisation (Ridge): Adds λΣwᵢ² to the loss. Penalises large weights heavily, pushing them towards zero but never exactly to zero. Creates smaller, distributed weights. Better when all features are relevant.
L1 Regularisation (Lasso): Adds λΣ|wᵢ| to the loss. Can push some weights exactly to zero, effectively performing feature selection. Better when you suspect many features are irrelevant.
Elastic Net: Combines both L1 and L2. λ controls total regularisation, and a ratio α controls the L1/L2 mix. Often outperforms either alone when both effects are desired.
1. Bootstrap Aggregating (Bagging): Each tree is trained on a different random sample (with replacement) of the training data. Each tree sees a different version of the data, so the trees are decorrelated.
2. Feature Randomness: At each split, only a random subset of features is considered (typically √d for classification). This ensures trees don't all rely on the same dominant features.
The final prediction is the majority vote (classification) or average (regression) across all trees. Averaging uncorrelated predictions reduces variance while keeping bias similar to a single tree.
Solutions:
1. ReLU activation: Derivative is 1 for positive inputs, so gradients don't shrink through ReLU layers.
2. Batch Normalisation: Normalises layer outputs, keeping gradients in a healthy range.
3. Residual connections (ResNets): Skip connections allow gradients to flow directly through the network, bypassing problematic layers.
4. Careful weight initialisation: Xavier/He initialisation sets initial weights appropriately for the activation function used.
Common forms:
1. Using test set data to tune hyperparameters or select features
2. Fitting a scaler (StandardScaler) on the entire dataset including test data before splitting
3. Including features in the training data that are derived from the target variable (e.g., "customer_churned_next_month" as a feature for churn prediction)
4. Time-series data: using future data to predict past events
Prevention: Always split your data first, then fit all preprocessing (scalers, imputers, encoders) only on the training set. Use sklearn Pipelines to ensure this is done correctly automatically.
When to use:
- You have a small labelled dataset (hundreds to thousands of examples) for a task similar to a task with large public datasets
- Training from scratch would be computationally prohibitive
- Similar domain: images → images, text → text
Approaches:
1. Feature extraction: Freeze all pretrained layers, only train a new classification head
2. Fine-tuning: Unfreeze some or all layers and continue training with a very small learning rate
Examples: Using ResNet50 (trained on ImageNet) for medical imaging; using BERT (trained on Wikipedia) for sentiment analysis; using GPT-3 for code generation with a few examples.
Recall = TP / (TP + FN) — of all the actual positives, how many did you catch? Use when false negatives are costly. Example: Cancer diagnosis — you don't want to miss actual cancer cases (false negatives are deadly).
F1 Score = 2 × (Precision × Recall) / (Precision + Recall) — harmonic mean of both. Use when you want a single metric that balances both, especially with imbalanced classes where accuracy is misleading.
ROC-AUC: Measures overall ranking quality across all classification thresholds. A score of 0.5 is random; 1.0 is perfect. Useful for comparing models independent of the decision threshold you set.
13AI/ML Learning Roadmap — Zero to Job-Ready
Follow this sequence. Don't jump to deep learning before you're solid on the fundamentals — every shortcut here comes back to haunt you in interviews.
Month 1 — Python & Math Foundations
Python basics (loops, functions, OOP), NumPy arrays, Pandas DataFrames. Linear algebra (matrices, vectors, dot products). Probability basics (Bayes' theorem, distributions). Statistics (mean, variance, correlation, hypothesis testing).
Month 2 — Core Machine Learning
Linear/Logistic Regression from scratch and with sklearn. Decision Trees, Random Forest, SVM, KNN. Model evaluation: cross-validation, confusion matrix, ROC-AUC. Feature engineering, preprocessing pipelines.
Month 3 — Data Science Skills
EDA with Pandas and Seaborn. Data cleaning and preprocessing. Kaggle competitions (start with Titanic, House Prices). Build 2-3 end-to-end ML projects. Learn Matplotlib for visualisation.
Month 4 — Advanced ML & Ensembles
Gradient Boosting (XGBoost, LightGBM, CatBoost). Hyperparameter tuning (GridSearchCV, Optuna). Advanced feature engineering. Handling imbalanced datasets. Time series forecasting basics.
Month 5 — Deep Learning Basics
Neural networks with TensorFlow/Keras. CNNs for image classification. RNNs/LSTMs for sequence data. Transfer learning. GPU training fundamentals (Google Colab is free).
Month 6 — NLP & Transformers
Text preprocessing, TF-IDF, word embeddings. BERT and fine-tuning with HuggingFace. Prompt engineering for LLMs. Build a chatbot or document QA system as a portfolio project.
Month 7-8 — MLOps & Deployment
REST APIs with FastAPI/Flask. Docker basics for model packaging. MLflow for experiment tracking. Basic cloud deployment (Render, HuggingFace Spaces, Google Cloud Run). Model monitoring and drift detection.
Month 9-12 — Portfolio & Job Prep
3-5 strong GitHub projects with documentation. Kaggle Expert rank. Practice ML system design questions. Revise all interview Q&A. Apply to data analyst → data scientist → ML engineer roles progressively.
14Free Resources — Curated for Indian Students
All resources below are completely free. No paid courses needed to become job-ready in AI/ML.
Courses
- Andrew Ng — Machine Learning Specialisation (Coursera): Audit for free. The gold standard introduction to ML. Cover all 3 courses.
- fast.ai — Practical Deep Learning: Top-down, code-first approach. Best for building real projects quickly before diving into theory.
- Google ML Crash Course: Free, well-structured, with interactive exercises. Good for absolute beginners.
- Andrej Karpathy — Neural Networks: Zero to Hero (YouTube): Build GPT from scratch. The most respected deep learning course on YouTube.
- StatQuest with Josh Starmer (YouTube): Explains every ML concept with unbeatable clarity. Watch before any interview.
Practice Platforms
- Kaggle: Free datasets, notebooks, competitions. Titanic is the canonical first competition.
- Google Colab: Free GPU/TPU access. No setup required. Use for all deep learning projects.
- HuggingFace: Free model hub and datasets. Best place to experiment with transformers and LLMs.
- LeetCode / GFG: SQL and Python problems — data engineers and analysts are tested on these.
Books (Free PDFs available legally)
- Hands-on ML with Scikit-Learn, Keras and TensorFlow — Aurélien Géron: Best practical ML book in print. Clear code examples throughout.
- Deep Learning — Goodfellow, Bengio, Courville: The theoretical bible. Available free at deeplearningbook.org.
- Pattern Recognition and Machine Learning — Bishop: Graduate-level theory. Start after you're comfortable with basics.