1/152
Looks like no tags are added yet.
Machine learning (definition)
The science of programming computers so they learn from data instead of following hand-written rules.
Arthur Samuel's definition of ML (1959)
A field of study that gives computers the ability to learn without being explicitly programmed.
Herbert Simon's definition of learning (1983)
Any change in a system that lets it perform better the second time on the same task, or on another task from the same population.
Tom Mitchell's definition of ML (1997)
A program learns from experience E with respect to tasks T and performance measure P if its performance on T, measured by P, improves with E.
Mitchell's E, T, P for a spam filter
E = labeled emails; T = flag spam; P = fraction of emails correctly classified.
AI vs. ML vs. deep learning
AI (machines mimicking human intelligence) contains ML (learning from data), which contains deep learning (many-layer neural networks).
Traditional programming vs. ML
Traditional: data + program → output. ML: data + output → program.
4 reasons to use ML
1) Problems needing long rule lists or constant fine-tuning; 2) fluctuating environments (retrain on new data); 3) insight into complex problems and big data; 4) problems with no good traditional solution.
Classic ML tasks
Pattern recognition (faces, speech, handwriting), pattern generation (image synthesis), anomaly detection (fraud), prediction (stocks, ECG, weather).
Collaborative vs. content-based recommender
Collaborative: recommends what similar users liked. Content-based: recommends items similar to what this user liked.
Forms of knowledge a learner acquires
Facts, patterns, concepts (generalized classes), rules (P → Q), models (abstract representations like v = d/t), skills.
Why ML is 'ill-posed'
We only see a limited sample of the world, so many models fit the data; the goal is one that generalizes beyond the dataset and ignores noise.
Occam's razor vs. Einstein (model simplicity)
Occam: the simplest explanation tends to be right (upper bound on complexity). Einstein: as simple as possible, but not simpler (lower bound).
Underfitting
Model too simple; high bias; misses patterns; does poorly on both training and test data. (The student who doesn't pay attention.)
Overfitting
Model too complex; high variance; memorizes noise; great on training data, poor on new data. (The student who memorizes: ~98% quiz, fails new exam questions.)
Best fit
Model that learns the real pattern and generalizes: good on training and test data. (The student who learns the concepts.)
Inductive bias
The set of assumptions an algorithm uses to choose a model; without it a learner could only memorize the training set.
Restriction bias
Inductive bias that limits which models the algorithm will consider at all.
Preference bias
Inductive bias that makes the algorithm prefer some models over others.
3 criteria for classifying ML systems
1) Type of supervision; 2) online vs. batch (can it learn incrementally?); 3) instance-based vs. model-based. The criteria are not exclusive.
Instance-based vs. model-based learning
Instance-based: compares new points to stored known points. Model-based: detects patterns and builds a predictive model.
Instance
One row (one example) in a dataset.
Features / feature vector
The input attributes (columns) used to make a prediction.
Label / class
The output value the model predicts in supervised learning.
Supervised learning
Learning a function f: X → Y from labeled training data (the learning process is called training).
Regression
Supervised task predicting a continuous value (e.g., tomorrow's temperature = 85°F); find the best-fit function.
Classification
Supervised task predicting a discrete category (e.g., hot or cold); find the decision boundary that separates the classes.
Multi-class classification
Many possible classes, but each instance belongs to exactly one.
Multi-label classification
Each instance can have several non-exclusive labels at once (e.g., Dog = True, Cat = True, Bird = False).
Discretization (binning)
Converting numerical values to categories: equal-width intervals, equal-frequency intervals, or custom thresholds.
Equal-width vs. equal-frequency binning
Equal-width: every bin covers the same range of values. Equal-frequency: every bin holds roughly the same number of items.
Unsupervised learning
Learning from unlabeled data: clustering, association rule mining, feature selection. If labels exist, supervised learning is better.
Clustering
Unsupervised grouping of instances with similar properties (partitional, hierarchical, density-based, model-based).
Outlier analysis
Unsupervised task looking for points that don't fit any cluster (e.g., fraud detection).
Association rule mining
Finding rules X → Y that predict an item from other items in a transaction (e.g., {Bread, Milk} → {Diaper}); algorithms: Apriori, FP-growth.
Support (association rules)
Fraction of all transactions that contain X ∪ Y. Example: {Bread, Milk, Diaper} in 2 of 5 transactions → 0.4.
Confidence (association rules)
count(X ∪ Y) / count(X): how often Y appears when X does. Example: {Bread, Milk} → {Diaper} = 2/3 = 0.67.
Feature selection
Choosing the most useful input attributes; methods: correlation/covariance matrix, information gain, Fisher's LDA, PCA.
Semi-supervised learning (weak supervision)
Uses a small labeled set plus a large unlabeled set, because labels are expensive and unlabeled data is cheap.
Requirement for semi-supervised learning
The unlabeled data must be relevant to the task: p(x) must carry information about p(y|x).
Self-training (pseudo-labeling)
Train on labeled data → label the unlabeled data with that model → add the most confident pseudo-labels → retrain.
Unsupervised pre-processing (semi-supervised)
Learn a representation from unlabeled data (often with an autoencoder); the final model trains only on the human-labeled points.
Cluster-then-label
Semi-supervised method: an unlabeled point gets the majority label of its cluster.
Active learning
A transductive method that picks which unlabeled samples would be most useful to label by hand.
Self-supervised learning
Generates its own labels from unlabeled data using a pretext task; no human labels needed.
Pretext task
A task built from the data itself to learn representations, e.g., predict a masked word, image completion, rotation prediction, jigsaw puzzles, colorization.
Self-supervised vs. semi-supervised
Semi-supervised uses a small human-labeled set plus unlabeled data; self-supervised creates its supervision from unlabeled data alone.
Self-supervised vs. unsupervised
Both use unlabeled data; unsupervised discovers structure, self-supervised sets up a specific prediction task.
Reinforcement learning
An agent takes actions, receives rewards, and learns a policy that maximizes long-term reward. Training data is optional.
Exploration vs. exploitation
Exploration: trying new actions. Exploitation: favoring actions that have paid off. RL balances both.
Model-based vs. model-free RL
Model-based: dynamic programming on the Bellman equations (policy iteration, value iteration). Model-free: Monte Carlo, temporal difference, SARSA, Q-learning, DQN.
Is RL supervised or unsupervised?
Neither, but both: rewards guide it like supervision, but no explicit goals or labels are given (learned by trial and error).
Deep learning
A technique (many-layer neural networks), NOT a learning paradigm; it can be used inside supervised, unsupervised or RL.
Deep learning vs. traditional ML
DL learns features automatically but needs more data and compute (GPUs) and is harder to interpret; traditional ML often needs manual feature engineering but works with less data.
Transfer learning
Adapting a model trained on one task to a related task (e.g., VGG, ResNet, BERT, GPT). It's about where the model starts.
Batch vs. online learning
Batch: trains once on the whole dataset. Online: updates incrementally as data arrives (big or streaming data). It's about how the model updates.
Is transfer learning a type of online learning?
No. Transfer is about the starting point; online is about updating. A transfer-learning model can use batch or online learning.
Ensemble learning
Combining multiple models for better predictions (e.g., random forests, Bayes optimal classifier); costs: model compatibility and computing resources.
Typical ML project steps
Big picture → get data → explore & visualize → prepare data → select & train model → fine-tune → present → launch, monitor, maintain.
Big-picture questions
What is the objective (it decides the performance measure; the model isn't the goal)? What does the current solution look like (the baseline)?
pandas Series vs. DataFrame
Series: one column. DataFrame: a 2-D table made of Series.
Exploratory data analysis (EDA)
Data-driven, visual first look at the data: univariate (1 variable), bivariate (2), multivariate (3+).
Why do EDA only on the training set?
To avoid data snooping bias: looking at test data leaks information into your modeling choices.
Handling missing values
Count NA/nulls (watch for fake values like 0 or −1), then drop rows/columns or impute (mean or median).
Numerical vs. categorical variables
Numerical: natural order, can average (continuous/discrete). Categorical: no natural order, can't average (nominal/ordinal).
Ordinal (label) encoding
Assign one integer per category (Green = 1, Red = 2, Black = 3). Implies an order, so it suits ordinal data like class standing.
One-hot encoding
One new 0/1 column per category. No false order, but creates a sparse matrix with many columns.
Encode Standing = Freshman, Junior, Freshman, Senior
Ordinal (natural order): 0, 2, 0, 3. One-hot: Freshman [1,0,1,0], Junior [0,1,0,0], Senior [0,0,0,1].
Why feature scaling?
Features on very different scales (age 18–80 vs. income $20k–$200k) bias models toward large-unit features; SVMs and gradient descent are especially sensitive.
Min-max scaling (normalization)
x' = (x − min) / (max − min), mapping to [0, 1]. Highly sensitive to outliers.
Min-max scaling to any range [a, b]
x_norm = (x − x_min) / (x_max − x_min) × (b − a) + a; e.g., [−1, 1] with MinMaxScaler(feature_range=(-1, 1)).
Standardization (z-score)
z = (x − μ) / σ: mean 0, standard deviation 1. Range is unbounded; less affected by outliers. StandardScaler().
Custom transformers
Apply a function such as log or sqrt (FunctionTransformer(np.log)) or combine features, e.g., rooms_per_house = total_rooms / households.
Typical train/test split
80% training, 20% testing. Training set as large as possible; test set representative.
Danger of using the first 80% of rows for training
If the data is sorted, the test set won't look like the training set.
Random sampling
Every row has an equal chance of selection; doesn't guarantee the test set keeps the full data's proportions. train_test_split(data, test_size=0.2, random_state=42).
Stratified sampling
Divide into homogeneous subgroups (strata) first so the test set keeps the same proportions of an important column. stratify=data['col'].
k-fold cross-validation
Split training data into k folds; train on k−1 and validate on the remaining one, rotating k times and averaging. cross_val_score(model, X, y, cv=5).
Validation set
Split data into train / validation / test: tune hyperparameters on validation, retrain the best model on all training data, then use the test set once.
Hyperparameter
A setting of the training algorithm or preprocessing that the model does not learn itself (e.g., C, α, learning rate, polynomial degree).
Why evaluate models?
To compare models quantitatively on the same data and to find good hyperparameter values.
True/False and Positive/Negative in a confusion matrix
True/False: did the prediction match the truth? Positive/Negative: what did the model predict?
Confusion matrix
Table of actual vs. predicted: TP, FN (actual positives), FP, TN (actual negatives). Also called a contingency table.
False positive (FP)
Actually negative, predicted positive: a false alarm.
False negative (FN)
Actually positive, predicted negative: a miss.
Accuracy
(TP + TN) / All: the fraction classified correctly.
Error rate
(FP + FN) / All = 1 − accuracy.
Class imbalance problem
When one class is rare, accuracy is misleading: if 5% are positive, always predicting negative is 95% accurate and useless.
Precision
TP / (TP + FP). Exactness: of everything predicted positive, how much really is positive?
Recall
TP / (TP + FN) = TP / P. Completeness: of all actual positives, how many did the model catch? Same as sensitivity and TPR.
Sensitivity
True positive rate = TP / (TP + FN). The same thing as recall.
Specificity
True negative rate = TN / (TN + FP) = TN / N: of all actual negatives, how many were correctly identified?
False positive rate (FPR)
FP / (FP + TN) = 1 − specificity: the fraction of negatives wrongly flagged as positive.
F1 score
2 × precision × recall / (precision + recall): the harmonic mean; high only when both are high. Use when FP and FN both matter.
Precision/recall trade-off
Raising the decision threshold increases precision and lowers recall; lowering it does the opposite.
Precision-recall curve
Plots precision and recall against the decision threshold.
ROC curve
Plots true positive rate (recall) against false positive rate across thresholds. Good classifiers hug the upper-left; random ones lie on the diagonal.
AUC
Area under the ROC curve: 1.0 = perfect, 0.5 = random guessing. Used to compare classifiers.
One-versus-All (OvA / One-vs-Rest)
Multiclass strategy: one binary classifier per class, each class vs. all others. N classes → N classifiers.
One-versus-One (OvO)
Multiclass strategy: one classifier per pair of classes. N classes → N(N−1)/2 classifiers.