liveBook · Manning

Step function

As explained in Grokking Machine Learning

A threshold function that maps an input to one of discrete constant values according to whether the input crosses a specified threshold.

A step function turns a score into a discrete prediction: it returns 1 when the input is nonnegative and 0 when the input is negative. section 5.1

For a perceptron, calculate a weighted score first, then apply the step function: ŷ = step(ax₁ + bx₂ + c). The threshold divides the input space into two zones. section 5.1

Use the function in three straightforward steps:

  • Represent labels numerically, such as happy = 1 and sad = 0. section 5.1
  • Compute the model score from the features, weights, and bias. section 5.4
  • Return 1 for a score of zero or greater; otherwise return 0. section 5.4

Classifying alien moods

Suppose a classifier scores an alien sentence using the counts of words such as aack and beep. A nonnegative score predicts happy, while a negative score predicts sad. The same rule works when the classifier separates points with a line or separates higher-dimensional data with a plane. section 5.1 section 5.4

Figure 5.8 The step function is useful in the study of perceptron models. The output of the step function is 0 when the input is negative and 1 otherwise.

View the graph showing the abrupt change from output 0 for negative inputs to output 1 otherwise. section 5.1

How Grokking Machine Learning covers it

How deep it goes
Defines the threshold rule, writes its formula, graphs its output, and implements it in Python before using it in a perceptron.
Examples
Uses alien moods, word-count features, separating lines, and Python prediction code as concrete examples.
What it assumes
Assumes numerical features and labels, then builds from score calculation to thresholded prediction.
What you can do after
Apply it via a Python prediction function to convert a perceptron score into a binary label.
How it connects
Links binary classification to perceptrons, activation functions, linear classifiers, and gradient descent.

Also explained in

Compare how 2 books explain step function →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Machine Learning. The section links point to the parts of the book it draws on.