5 questions across Easy, Medium, and Hard levels
Classification predicts a discrete category/class label. Examples: spam/not-spam, disease/no disease, digit recognition (0-9). Metrics: accuracy, precision, recall, F1, AUC-ROC. Regression predicts a continuous numerical value. Examples: house price, temperature, stock price. Metrics: MAE, MSE, RMSE, R². Some algorithms do both (decision trees, neural networks).
KNN classifies a new point based on the majority class of its K nearest neighbors (by distance - usually Euclidean). Steps: 1) Choose K. 2) Calculate distance from new point to all training points. 3) Select K nearest neighbors. 4) Majority vote for classification, average for regression. Pros: simple, no training phase. Cons: slow prediction on large datasets, sensitive to scale (normalize features!), curse of dimensionality.
Random Forest is an ensemble of many decision trees. Improvements: 1) Bagging: each tree trained on random subset of data (bootstrap). 2) Feature randomness: each split considers random subset of features. 3) Averaging predictions reduces variance/overfitting. Single trees are interpretable but overfit. Random Forests are more accurate and robust but less interpretable. Feature importance is a useful byproduct.
Precision = TP/(TP+FP): of all predicted positives, how many were actually positive? (minimize false positives). Recall = TP/(TP+FN): of all actual positives, how many did we catch? (minimize false negatives). F1 = 2*(Precision*Recall)/(Precision+Recall): harmonic mean, balance between precision and recall. Use precision when false positives are costly (spam). Use recall when false negatives are costly (cancer detection).
Attention allows models to focus on relevant parts of input when generating each output. Self-Attention: Query (Q), Key (K), Value (V) matrices computed from input. Attention(Q,K,V) = softmax(QK^T/√dk)V. Each token attends to all other tokens, weighted by relevance. Multi-head attention runs attention h times in parallel capturing different relationships. Transformers stack attention + feed-forward layers, enabling parallelization and capturing long-range dependencies (unlike RNNs).