1. Home
  2. Explore
  3. Mathematics
  4. Linear Regression

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Linear Regression

Machine Learning: Core Concepts, Representations, Distance, and Basic Learning Methods

What Machine Learning Is

Machine learning is the study of methods that allow computers to learn useful patterns from data rather than requiring every rule to be explicitly programmed.

A machine-learning system generally:

  1. Receives examples or observations.

  2. Represents those examples using measurable features.

  3. Infers a model or rule from the examples.

  4. Uses the learned model to make predictions about new, unseen examples.

A widely used definition describes machine learning as a field that gives computers the ability to learn without being explicitly programmed.

The central goal is generalization: learning a pattern from known data that remains useful when applied to new data.

Traditional Programming Compared with Machine Learning

In traditional programming:

  • A programmer writes a program containing the rules or procedure.

  • The computer receives input data.

  • The program processes the data and produces output.

This can be represented as:

Program+Data→Output\text{Program} + \text{Data} \rightarrow \text{Output}Program+Data→Output

In machine learning:

  • The computer receives examples, often including desired outputs or labels.

  • A learning algorithm infers a model or program from those examples.

  • The resulting model is applied to new inputs.

This process can be represented as:

Data+Desired Outputs→Learned Model\text{Data} + \text{Desired Outputs} \rightarrow \text{Learned Model}Data+Desired Outputs→Learned Model

The learned model can then be used as:

Learned Model+New Data→Predictions\text{Learned Model} + \text{New Data} \rightarrow \text{Predictions}Learned Model+New Data→Predictions

Examples of Learning-Like Computation

Not every algorithm learns in the same meaningful sense.

  • A square-root algorithm based on Newton’s method performs a prescribed procedure. It could be viewed loosely as learning how to approximate a square root, but its behavior is explicitly designed by the programmer.

  • Linear regression is more clearly learning-like because the program receives experimental data and infers a mathematical relationship from it.

  • A spring experiment can provide mass–displacement data. Regression can infer the relationship between mass and displacement and use that relationship to predict the displacement produced by a new mass.

Linear regression therefore contains the main elements of machine learning:

  • Training observations

  • Inference about an underlying process

  • A model that predicts previously unseen cases

Machine Learning in Practice

Machine learning is used extensively across computing and science. Important applications include:

  • Game playing: Systems such as AlphaGo learned strategies capable of defeating world-class Go players.

  • Recommendation systems: Netflix, Amazon, and similar services predict what users may want to watch or purchase.

  • Online advertising: Advertising systems use information about user preferences and behavior to select advertisements.

  • Drug discovery: Algorithms help identify promising compounds and relationships in biological data.

  • Character recognition: Postal systems use machine learning and computer vision to recognize handwritten characters.

  • Financial modeling: Investment and hedge-fund companies use machine-learning methods to analyze markets.

  • Speech assistants: Systems such as Siri use machine learning to recognize and interpret spoken language.

  • Driver assistance: Computer-vision systems identify vehicles and obstacles and can activate braking or other safety functions.

  • Autonomous driving: Machine learning is a major component of systems designed to drive without human control.

  • Face recognition: Systems detect and recognize faces in images.

  • Medical diagnosis: Systems such as IBM Watson have been applied to tasks including cancer diagnosis.

  • Natural language processing, computational biology, computer vision, and robotics: These fields depend heavily on machine-learning techniques.

Modern systems such as convolutional neural networks and deep-learning models are highly sophisticated, but they still rely on fundamental ideas such as data representation, similarity, optimization, prediction, and evaluation.


Learning from Experience

A machine-learning system is intended to learn from experience and use that experience to infer new facts or make predictions.

An early influential example was a checkers-playing program that improved by analyzing the results of its own games. Rather than being given a complete strategy for every possible board position, the program used experience to adjust its behavior.

The progression from checkers to chess and then to Go illustrates how learning systems have become increasingly powerful, but the underlying idea remains the same:

  • Observe outcomes.

  • Identify patterns associated with success or failure.

  • Modify the model or strategy.

  • Use the revised model in later situations.

Memorization Versus Inference

There are two broad ways to acquire knowledge.

Memorization

A system can memorize individual facts or examples.

  • Memorized information is useful when future questions repeat known cases.

  • It does not necessarily help with new situations.

  • It corresponds to storing explicit statements of truth, sometimes called declarative knowledge.

A memorization-based system may perform well on data it has already seen but poorly on unfamiliar examples.

Inference and Generalization

A stronger system infers new information from existing observations.

  • It identifies implicit patterns.

  • It uses those patterns to derive conclusions about new cases.

  • It corresponds more closely to procedural or imperative knowledge, because it captures ways of reaching new conclusions.

Machine learning seeks to infer useful rules from patterns that are not explicitly stated in the training data.

The goal is not simply to remember examples, but to discover a model that can make useful predictions about examples that have not yet been observed.


The Basic Machine-Learning Paradigm

Most introductory machine-learning problems can be organized into three stages.

1. Training Data

The system receives a collection of observations or examples.

Each example may include:

  • A set of measurable properties, called features

  • A known output or label, in supervised learning

  • No known output, in unsupervised learning

For example, a spring dataset may contain:

  • The mass attached to the spring

  • The measured displacement of the spring

A football-player dataset may contain:

  • Height

  • Weight

  • Position played

2. Model Inference

The learning algorithm attempts to infer the process or pattern that generated the data.

Examples include:

  • Fitting a line to mass–displacement observations

  • Finding a boundary separating football positions

  • Grouping similar players when their positions are unknown

3. Prediction

The learned model is applied to new examples.

Examples include:

  • Predicting the displacement caused by a new mass

  • Predicting the position of a new football player

  • Assigning an unlabeled animal to a natural group

The model must be evaluated on data that were not used to construct it. Otherwise, it may appear successful simply because it memorized the training examples.


Supervised and Unsupervised Learning

Supervised Learning

In supervised learning, every training example has a known label or target output.

The algorithm uses labeled examples to learn a rule that predicts labels for new inputs.

Examples:

  • Classifying a football player as a receiver or lineman

  • Determining whether an animal is a reptile

  • Predicting whether an email is spam

  • Predicting a numerical quantity such as spring displacement

The training process can be described as:

  1. Observe examples with features and labels.

  2. Search for a rule that relates features to labels.

  3. Apply the rule to new, unlabeled examples.

  4. Evaluate how often the predicted labels match the actual labels.

Supervised learning is called “supervised” because the known labels provide guidance during learning.

Unsupervised Learning

In unsupervised learning, the examples do not have known labels.

The algorithm attempts to discover natural groupings or structures in the data.

Typical goals include:

  • Finding clusters of similar examples

  • Identifying groups that are close together

  • Determining whether the data naturally separate into several categories

  • Assigning new observations to discovered groups

Unsupervised learning may be used when:

  • The number of groups is known in advance.

  • The number of groups must itself be estimated.

  • No human has provided category labels.

Classification and Clustering

The two broad methods correspond closely to the learning settings:

  • Classification: Usually supervised; uses labeled data to assign new examples to known categories.

  • Clustering: Usually unsupervised; discovers groups in data without requiring known labels.


Representing Examples with Features

Feature Vectors

A machine-learning algorithm needs a structured representation of each example. The representation is often a feature vector.

A feature vector lists measurable properties of an object:

x=(x1,x2,…,xn)\mathbf{x} = (x_1, x_2, \ldots, x_n)x=(x1​,x2​,…,xn​)

Each component represents one feature or dimension.

For football players, a feature vector might be:

x=(height,weight)\mathbf{x} = (\text{height},\text{weight})x=(height,weight)

For animals, the vector might include:

  • Whether the animal lays eggs

  • Whether it is cold-blooded

  • Whether it has scales

  • Whether it is poisonous

  • Number of legs

Boolean features can be encoded numerically:

  • True →1\rightarrow 1→1

  • False →0\rightarrow 0→0

The resulting vector could contain several binary components and one integer-valued component.

Feature Selection

Feature selection is the process of deciding which measurable properties should be included in the representation.

Useful features:

  • Contain information relevant to the prediction.

  • Help distinguish between classes.

  • Improve the signal available to the learning algorithm.

Poor features:

  • Are unrelated to the target.

  • Add random variation.

  • Can cause the algorithm to discover accidental correlations.

  • May increase overfitting.

Football-Player Example

Height and weight are convenient features for distinguishing football positions, but they may not be the best possible features.

Other potentially useful features could include:

  • Running speed

  • Arm length

  • Strength

  • Agility

  • Average performance measures

  • Other physical or behavioral characteristics

A feature is valuable not merely because it is easy to measure, but because it helps explain the distinction the algorithm is trying to learn.

Predicting Student Performance

Suppose a system attempts to predict a student’s performance in a programming course.

Potentially useful features include:

  • Prior grade-point average

  • Previous programming experience

  • Performance in related courses

Potentially irrelevant features might include:

  • Birth month

  • Astrological sign

  • Eye color

Including every available feature is risky. A learning algorithm might find a coincidental relationship between irrelevant features and the target. Such a relationship may fit the training data but fail on new students.

Feature Engineering

Feature engineering involves deciding:

  1. Which features to measure.

  2. How to encode those features numerically.

  3. How to scale the feature dimensions.

  4. Whether some features should receive greater or lesser influence.

The quality of the feature representation can strongly affect the quality of the learned model.

Good feature engineering increases the signal-to-noise ratio by emphasizing informative properties and reducing irrelevant variation.

Feature Scale

Feature dimensions may use different numerical scales.

For example:

  • Height might range from roughly 60 to 80 inches.

  • Weight might range from roughly 150 to 350 pounds.

  • A binary feature ranges only from 0 to 1.

  • Number of legs might range from 0 to 4.

If distance is computed directly, a feature with a larger numerical range can dominate the result even if it is not more important conceptually.

This distinction is important:

  • Scaling concerns the numerical range or units of a feature.

  • Weighting concerns intentionally assigning different importance to features.

A feature should not dominate merely because it is measured in larger numerical units.


Measuring Similarity and Distance

Machine-learning algorithms often depend on determining whether two examples are close or far apart.

Distance can be used to:

  • Group similar examples together.

  • Assign a new example to the nearest known group.

  • Construct a boundary separating different classes.

  • Identify the nearest labeled examples for classification.

If examples are represented by vectors x\mathbf{x}x and y\mathbf{y}y, a distance function computes a nonnegative quantity d(x,y)d(\mathbf{x},\mathbf{y})d(x,y).

The Minkowski Metric

A general family of distance measures is the Minkowski metric.

For vectors x\mathbf{x}x and y\mathbf{y}y with nnn components, and a positive parameter ppp, the distance is:

d(x,y)=(∑i=1n∣xi−yi∣p)1/pd(\mathbf{x},\mathbf{y}) = \left( \sum_{i=1}^{n} \left|x_i-y_i\right|^p \right)^{1/p}d(x,y)=(∑i=1n​∣xi​−yi​∣p)1/p

Different choices of ppp produce different distance measures.

Manhattan Distance

When p=1p=1p=1:

d1(x,y)=∑i=1n∣xi−yi∣d_1(\mathbf{x},\mathbf{y}) = \sum_{i=1}^{n}|x_i-y_i|d1​(x,y)=∑i=1n​∣xi​−yi​∣

This is called Manhattan distance because movement is imagined as occurring along perpendicular streets rather than directly through the plane.

Characteristics:

  • Differences are added directly.

  • It is often useful when movement is constrained to separate dimensions.

  • It can be less sensitive than Euclidean distance to a single large difference.

Euclidean Distance

When p=2p=2p=2:

d2(x,y)=∑i=1n(xi−yi)2d_2(\mathbf{x},\mathbf{y}) = \sqrt{ \sum_{i=1}^{n}(x_i-y_i)^2 }d2​(x,y)=∑i=1n​(xi​−yi​)2​

This is the ordinary straight-line distance in geometric space.

Characteristics:

  • Large coordinate differences are emphasized because they are squared.

  • It is the most familiar geometric distance.

  • It works naturally when dimensions have comparable scales and meanings.

Why the Choice of Metric Matters

Two objects can have different relative distances depending on the metric used.

For example, if one pairing differs by moderate amounts across several dimensions and another pairing differs by one especially large amount, then:

  • Manhattan distance adds each difference directly.

  • Euclidean distance squares the differences, making the large difference more influential.

Thus, the “closest” examples can change when the distance metric changes.


Clustering: Learning from Unlabeled Data

Purpose of Clustering

Clustering attempts to divide unlabeled examples into groups such that:

  • Examples within the same group are close to one another.

  • Different groups are relatively far apart.

  • The average within-group distance is as small as possible, subject to reasonable model constraints.

A clustering algorithm is not given the correct group labels. It must infer the natural structure of the data.

A Basic Iterative Clustering Procedure

A standard distance-based clustering method works approximately as follows:

  1. Choose the desired number of clusters, kkk.

  2. Select kkk initial examples as cluster representatives or exemplars.

  3. Assign every other example to the nearest exemplar.

  4. For each resulting cluster, identify a central representative, often using a median-like example.

  5. Replace the old exemplars with the new representatives.

  6. Reassign examples to the nearest representatives.

  7. Repeat until the assignments stabilize or a specified number of iterations has been completed.

The procedure seeks clusters with small within-cluster distances.

Choosing Initial Exemplars

Random selection is possible, but poor initial choices can lead to poor clusters.

A better strategy may attempt to select initial exemplars that are relatively far apart. If the initial exemplars are too similar, they may attract overlapping groups and produce an inferior result.

Median Representatives

The representative of a cluster may be chosen as the example closest to the center of the cluster.

This is different from using the arithmetic mean:

  • The mean may be a point that is not actually one of the examples.

  • The median exemplar is an actual example near the cluster’s center.

Football-Player Clustering Example

Suppose a dataset contains five receivers and five linemen, represented by height and weight.

Although the clustering algorithm is not given the positions, it may discover groups based on physical similarity.

Using Weight Alone

Weight may produce a fairly natural division:

  • A group of lighter players

  • A group of heavier players

The groups may correspond reasonably well to receivers and linemen.

Using Height Alone

Height may produce a less clear division because the two positions overlap more substantially in height.

Using Height and Weight

Using both features may create a clearer separation in a two-dimensional plot.

A boundary can be drawn between the cluster centers. The boundary consists of points that are equally distant from the two centers.

For a new player:

  • A point on one side of the boundary is assigned to one cluster.

  • A point on the other side is assigned to the other cluster.

  • A point near the boundary may be ambiguous.

Selecting the Number of Clusters

The number of clusters is a model constraint.

If too few clusters are chosen:

  • Naturally distinct groups may be combined.

  • The clusters may have large internal variation.

If too many clusters are chosen:

  • The algorithm may split meaningful groups unnecessarily.

  • It may overfit the training data.

  • Every example could become its own cluster, producing perfect internal distance but no useful generalization.

For example, with 100 examples, choosing 100 clusters would make each example its own cluster. Each point would be maximally close to its own cluster representative, but the result would not provide a useful classification system.

A good number of clusters should balance:

  • Tightness within each cluster

  • Separation between clusters

  • Simplicity

  • Generalization to new data

Validating Clusters

Clusters should be evaluated using data not used to create them.

In the football example, newly added running-back data can test whether the clusters provide useful assignments.

  • One running back may be clearly closer to the receiver cluster.

  • Another may lie almost exactly between the receiver and lineman clusters.

An ambiguous point may indicate:

  • The data do not support a clean two-cluster model.

  • The example is genuinely intermediate.

  • A third cluster may be appropriate.

  • The distance measure or feature representation may need revision.

When three clusters are used, the data may separate into:

  • A group of larger players

  • A group of smaller players

  • An intermediate group

If the average within-cluster distances decrease substantially, the three-cluster model may be preferable.

However, additional clusters should not be introduced merely to explain every difficult point. A complicated clustering structure may be an example of overfitting.


Classification: Learning from Labeled Data

Purpose of Classification

Classification assigns examples to predefined categories.

In supervised classification, each training example has:

  • A feature vector

  • A known class label

The algorithm learns a rule that predicts the class of a new example.

Examples include:

  • Receiver versus lineman

  • Reptile versus non-reptile

  • Democrat versus Republican

  • Spam versus non-spam

Decision Boundaries

A classifier often creates a decision boundary separating regions associated with different classes.

Depending on the number of feature dimensions, the boundary may be:

  • A point in one dimension

  • A line in two dimensions

  • A plane or hyperplane in higher dimensions

  • A collection of line segments or more complex surfaces

Football-Player Example

If height and weight are features, the classifier may find a line separating receivers from linemen.

A simple rule might be:

  • Players above a certain weight are classified as linemen.

  • Players below that threshold are classified as receivers.

A new player is classified according to the side of the boundary on which the player falls.

Overfitting in Classification

A classifier should not be made unnecessarily complex.

A highly complicated boundary can classify every training example correctly but fail on new data. This is overfitting.

For example:

  • A single straight line may misclassify a few training examples but generalize well.

  • A highly irregular sequence of line segments may perfectly separate the training points but capture noise rather than the underlying pattern.

A practical classifier may need to tolerate some training errors in exchange for better performance on unseen data.

Overlapping Classes

Some examples may be too similar to separate reliably using the available features.

In the football example, a running back and a receiver may have nearly identical height and weight. No single boundary can distinguish them perfectly in that feature space.

This does not necessarily mean that the algorithm is defective. It may mean that:

  • The chosen features are insufficient.

  • The classes genuinely overlap.

  • The data contain noise.

  • The application requires accepting some classification errors.


The kkk-Nearest Neighbor Method

kkk-nearest neighbors, commonly abbreviated kkk-NN, is a classification method that uses labeled examples and distance.

For a new example:

  1. Compute its distance to every labeled training example.

  2. Identify the kkk closest examples.

  3. Examine their labels.

  4. Assign the new example the label receiving the majority vote.

  5. Leave the example unclassified if no sufficiently strong majority exists, depending on the implementation.

For example, if k=5k=5k=5:

  • Three of the five nearest examples are receivers.

  • Two are linemen.

  • The new player is classified as a receiver.

Effect of kkk

A small kkk:

  • Is sensitive to individual examples and noise.

  • Can produce irregular decision boundaries.

  • May overfit.

A larger kkk:

  • Produces smoother decisions.

  • Is less sensitive to individual points.

  • May overlook local structure or merge distinct groups.

The value of kkk is therefore a model-design choice that should be validated experimentally.


Choosing and Refining a Classification Model

A classifier can be designed in several ways.

Simple Separating Surface

The simplest approach is to find one line, plane, or hyperplane separating the classes.

Advantages:

  • Easy to interpret

  • Computationally simple

  • Less likely to overfit

Disadvantages:

  • Cannot represent complicated class shapes

  • May misclassify data when classes are not linearly separable

More Complicated Separating Surface

A model can use multiple lines or line segments to divide the feature space.

Advantages:

  • Can reduce training error

  • Can represent more complex patterns

Disadvantages:

  • May overfit

  • May perform poorly on test data

  • Is harder to interpret

Feature-Based Rule Refinement

A classifier can also be refined by changing the features used.

If a model fails on known examples, the algorithm or designer may:

  • Remove overly restrictive features.

  • Add useful features.

  • Re-encode a feature.

  • Change the scale of a feature.

  • Change the distance metric.

  • Accept some errors if perfect separation is impossible.


Reptile Classification Example

Consider a classifier that determines whether an animal is a reptile.

Potential features include:

  • Egg-laying

  • Scales

  • Poisonous

  • Cold-blooded

  • Number of legs

Initial Rule

If the first examples are snakes that:

  • Lay eggs

  • Have scales

  • Are poisonous

  • Are cold-blooded

  • Have no legs

a model might incorrectly conclude that all five properties are required for an animal to be a reptile.

Refining the Rule with Additional Examples

A boa constrictor is a reptile but may not lay eggs and is not poisonous. Therefore, egg-laying and poisonousness cannot be required features.

A more general rule may use:

  • Scales

  • Cold-bloodedness

  • Number of legs

A chicken is not a reptile and provides a useful negative example:

  • It may have scales.

  • It is not cold-blooded.

  • It has legs.

An alligator is a reptile but has legs, so a rule requiring zero legs fails.

The rule may then be modified to allow:

  • Zero legs or four legs

  • Scales

  • Cold-bloodedness

A dart frog is not a reptile and helps test whether the revised rule is too broad.

Inseparable Examples

A python is a reptile, while a salmon is not. However, if both are represented using only:

  • Scales

  • Cold-bloodedness

  • Number of legs

they may have identical or nearly identical feature values.

No classifier using only those features can distinguish them perfectly.

The designer must either:

  • Add a more informative feature.

  • Change the representation.

  • Accept some classification errors.

  • Choose which kind of error is more acceptable.

This demonstrates that a model cannot learn distinctions that are absent from its representation.


False Positives and False Negatives

When classes overlap, classification errors are commonly divided into two types.

False Positive

A false positive occurs when the classifier predicts that an example belongs to the target class, but it does not.

Example:

  • The classifier labels a salmon as a reptile.

  • The salmon is actually not a reptile.

False Negative

A false negative occurs when the classifier predicts that an example does not belong to the target class, but it actually does.

Example:

  • The classifier labels a true reptile as non-reptile.

The preferred error type depends on the application.

For example:

  • In disease screening, avoiding false negatives may be especially important.

  • In spam filtering, avoiding false positives may be especially important because legitimate messages should not be discarded.

Classification Trade-Off

A classifier may be adjusted to favor one type of error over the other.

A rule designed to identify nearly every target example may produce:

  • High sensitivity

  • More false positives

  • Low specificity

A rule designed to reject nearly every non-target example may produce:

  • High specificity

  • More false negatives

  • Low sensitivity

There is often no single model that simultaneously maximizes both measures.


Five Essential Components of Machine Learning

Every machine-learning method requires decisions in several major areas.

1. Training Data and Evaluation

The system must determine:

  • What examples will be used for training.

  • What examples will be reserved for validation or testing.

  • How success will be measured.

A model should not be judged only by its performance on the data it saw during learning.

2. Representation

The system must decide how each example will be represented.

Questions include:

  • Which features should be included?

  • How should nonnumeric information be encoded?

  • Are the chosen features relevant?

  • Does the representation preserve the distinctions needed for prediction?

3. Distance or Similarity

The system must determine how to compare examples.

Questions include:

  • Which metric should be used?

  • Should Euclidean or Manhattan distance be used?

  • Are all dimensions measured on compatible scales?

  • Should some dimensions contribute more than others?

4. Objective Function

The system needs a definition of what counts as a good model.

Examples include:

  • Low average distance within clusters

  • Large separation between clusters

  • High classification accuracy

  • Low prediction error

  • A balance between accuracy and model simplicity

5. Optimization Method

The algorithm must determine how to search for a model that improves the objective function.

Examples include:

  • Repeatedly updating cluster representatives

  • Searching for a separating line

  • Choosing the best value of kkk

  • Adjusting model parameters to reduce error

These components interact. A poor representation or distance measure can prevent even a sophisticated optimization method from finding a useful model.


Evaluating Classifiers

A classifier should be evaluated using clearly defined performance measures.

Training and Test Data

A common procedure is to divide labeled data into:

  • A training set, used to construct the model.

  • A test set, used to evaluate how well the model generalizes.

The test data should not influence the construction of the model.

A model that performs very well on training data but poorly on test data is likely overfitting.

Confusion Matrix

A confusion matrix compares predicted labels with actual labels.

For a binary classification problem, it contains four categories:

True Positive

The classifier predicts the target class, and the example truly belongs to that class.

True Negative

The classifier predicts the non-target class, and the example truly does not belong to the target class.

False Positive

The classifier predicts the target class, but the example actually belongs to the non-target class.

False Negative

The classifier predicts the non-target class, but the example actually belongs to the target class.

The diagonal entries of a confusion matrix represent correct classifications.

Accuracy

Accuracy is the fraction of all predictions that are correct:

Accuracy=True Positives+True NegativesTotal Number of Examples\text{Accuracy} = \frac{\text{True Positives}+\text{True Negatives}} {\text{Total Number of Examples}}Accuracy=Total Number of ExamplesTrue Positives+True Negatives​

A model with accuracy 0.700.700.70 correctly classifies 70%70\%70% of the examples.

Accuracy can be misleading when the classes are highly imbalanced. For example, a classifier that always chooses the majority class may achieve high accuracy while failing to detect the minority class.

Positive Predictive Value

Positive predictive value, or PPV, measures how many examples predicted as positive are actually positive:

PPV=True PositivesTrue Positives+False Positives\text{PPV} = \frac{\text{True Positives}} {\text{True Positives}+\text{False Positives}}PPV=True Positives+False PositivesTrue Positives​

A high PPV means that a positive prediction is usually reliable.

Sensitivity

Sensitivity, also called recall or true-positive rate, measures the proportion of actual positive examples correctly identified:

Sensitivity=True PositivesTrue Positives+False Negatives\text{Sensitivity} = \frac{\text{True Positives}} {\text{True Positives}+\text{False Negatives}}Sensitivity=True Positives+False NegativesTrue Positives​

A classifier with sensitivity 111 identifies all actual positive examples, but it may also incorrectly label many negative examples as positive.

Specificity

Specificity, or true-negative rate, measures the proportion of actual negative examples correctly rejected:

Specificity=True NegativesTrue Negatives+False Positives\text{Specificity} = \frac{\text{True Negatives}} {\text{True Negatives}+\text{False Positives}}Specificity=True Negatives+False PositivesTrue Negatives​

A classifier with specificity 111 correctly rejects all negative examples, but it may fail to identify actual positive examples.

Sensitivity–Specificity Trade-Off

The classifier’s decision threshold can often be adjusted to change the balance between sensitivity and specificity.

  • Increasing sensitivity generally increases the number of detected positives but may also increase false positives.

  • Increasing specificity generally reduces false positives but may increase false negatives.

Extreme strategies illustrate the trade-off:

  • Label every example as positive:

    • Sensitivity becomes 111.

    • Specificity may become 000.

  • Label every example as negative:

    • Specificity becomes 111.

    • Sensitivity becomes 000.

The appropriate balance depends on the consequences of the two error types.

ROC Curves

A receiver operating characteristic curve, or ROC curve, summarizes the trade-off between sensitivity and false-positive rate as the classifier threshold changes.

Because:

False Positive Rate=1−Specificity\text{False Positive Rate} = 1-\text{Specificity}False Positive Rate=1−Specificity

an ROC curve commonly plots:

  • Sensitivity on the vertical axis

  • False-positive rate on the horizontal axis

It helps evaluate how well a classifier distinguishes between classes across different decision thresholds.


Core Design Principles

Several principles recur across all the examples.

Similarity Depends on Representation

Two examples are similar only with respect to the features and distance measure being used.

A poor representation can make genuinely similar examples appear distant or make unrelated examples appear close.

Scale Can Distort Distance

A numerical feature with a much larger range than the others may dominate distance calculations.

Possible solutions include:

  • Rescaling features to comparable ranges.

  • Encoding a large-valued feature more appropriately.

  • Choosing a metric suited to the data.

  • Treating a feature as binary when only the presence or absence of a property matters.

More Features Are Not Always Better

Adding features can:

  • Provide useful information.

  • Increase noise.

  • Create accidental correlations.

  • Increase dimensionality.

  • Encourage overfitting.

The best representation contains informative features, not necessarily the largest possible number of features.

Model Complexity Must Be Controlled

A model should be complex enough to capture meaningful structure but simple enough to generalize.

This applies to:

  • The number of clusters

  • The shape of a classification boundary

  • The number of features

  • The choice of kkk in kkk-NN

  • The number of parameters in the model

Validation Is Essential

A model should be tested on examples that were not used to construct it.

Validation helps determine whether the model has learned:

  • A general pattern that applies to new data, or

  • Accidental details specific to the training set

A strong training result alone does not establish that a model has learned effectively. Generalization to unseen examples is the central test of machine learning.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent