liveBook · Manning

Binary random variable

As explained in Statistics Every Programmer Needs

A binary decision variable is a decision variable restricted to the values zero and one to represent a yes-or-no choice.

A binary variable has two possible values, commonly coded 0 and 1. In a classification dataset, it records which of two categories an observation belongs to. In an optimization model, a binary decision variable instead records a choice the model must make. The coding is similar, but an observed class and a chosen action have different roles. section 5.2 section 8.2

Classifying raisins

A dataset of 900 raisins has seven numeric measurements and a Class column identifying Kecimen or Besni. Map Kecimen to 0 and Besni to 1 before using Class as the dependent variable in logistic regression. Grouping measurements by Class then helps reveal differences between the varieties; the codes identify categories, not measured quantities. section 5.2 section 5.2.1

For feature selection, define one decision variable per candidate feature: 1 means selected and 0 means not selected. A linear objective can combine each selection with its priority score, while budget and strategic constraints limit feasible combinations. section 8.2

>>> x_bounds = [(0, 1) for _ in features]

The Python list comprehension creates a (0, 1) bound tuple for every feature. These bounds specify the range supplied to the solver; the intended decisions are discrete yes-or-no selections. section 8.2.5

How Statistics Every Programmer Needs covers it

How deep it goes
Works through class coding and Python bounds construction, but does not develop a probability distribution for the binary outcome.
Examples
Uses Kecimen-versus-Besni raisin labels and selected-versus-excluded project features.
What it assumes
Introduces the class coding and bound tuples explicitly while using basic Python and pandas operations.
What you can do after
Apply it via pandas class mapping or configure 0–1 bounds for feature-selection variables.
How it connects
Connects binary outcomes to logistic regression and categorical data, and binary decisions to linear objectives and constraints.

Also explained in

Compare how 3 books explain binary random variable →

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.