liveBook · Manning

Binary outcome

As explained in Statistics Every Programmer Needs

A binary outcome is a response variable with exactly two possible categories, conventionally represented by 0 and 1.

A binary outcome is a response with exactly two categories, typically coded 0 and 1. Logistic regression uses predictors to estimate P(Y = 1 | X): the probability that an observation belongs to the category coded 1. The choice of which category receives 1 is arbitrary, but it determines how the probabilities are interpreted. section 5.1 section 5.2.1

Unlike linear regression’s numeric prediction, logistic regression passes a linear combination of predictors through the sigmoid function, producing a probability between 0 and 1. With a 0.5 cutoff, probabilities at or above 0.5 become predictions of 1; those below it become predictions of 0. Keep the probability as well as the predicted class: the class alone hides how close the result was to the cutoff. section 5.1 section 5.2.3

Code a categorical outcome

For raisin classification, map the original variety labels before fitting: `class_mapping = {'Kecimen': 0, 'Besni': 1}` followed by `raisins['Class'] = raisins['Class'].map(class_mapping)`. Check the resulting column against the original labels. A subsequent probability for this outcome refers specifically to Besni, the category coded 1. section 5.2.1

Before using a binary prediction for a decision:

  • Explore predictor distributions by outcome class; grouped statistics and histograms can expose patterns and potential data issues. section 5.2.1 section 5.3
  • Check model fit and predictor relationships rather than treating a computed probability as sufficient evidence. McFadden’s pseudo R² compares fit with an intercept-only model; the likelihood-ratio and predictor p-values address statistical significance. section 5.2.3 section 5.3
  • Compare predicted classes with observed outcomes using true and false positive and negative rates, accuracy, misclassification, and area under the ROC curve. section 5.3
>>> print(raisins_subset.head(n = 3))
   MinorAxisLength  Perimeter  Class  probability  prediction
0           253.29    1184.04      0     0.698821           1
1           243.03    1121.79      0     0.525426           1
2           266.33    1208.58      0     0.713766           1

>>> print(raisins_subset.tail(n = 3))
     MinorAxisLength  Perimeter  Class  probability  prediction
897           298.84    1292.83      1     0.811597           1
898           254.18    1258.55      1     0.881365           1
899           215.27    1272.86      1     0.960193           1

The displayed raisin records retain the observed class beside the probability and thresholded prediction. The first three have observed class 0 but predictions of 1, making errors visible rather than reporting probabilities alone. section 5.2.3

The same outcome structure applies beyond logistic regression. A fourth-down football play either converts or fails; decision trees and random forests can be fitted to predict that result from play-by-play data. In either setting, define the two categories clearly before interpreting predictions or acting on them. section 6.2 section 5.2.1

How Statistics Every Programmer Needs covers it

How deep it goes
Works through outcome encoding, sigmoid probabilities, thresholded predictions, and checks of fit and classification performance.
Examples
Uses encoded raisin varieties, observed-versus-predicted raisin records, and professional football fourth-down conversions.
What it assumes
Assumes labeled records and predictor variables while teaching how to convert raw categorical outcome labels into 0 and 1.
What you can do after
Apply it via pandas and logistic regression to encode two classes, interpret predicted probabilities, and evaluate classification errors.
How it connects
Connects logistic regression, the sigmoid function, classification thresholds, pseudo R², decision trees, and random forests.

Also explained in

Compare how 4 books explain binary outcome →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.