liveBook · Manning

Binary feature

As explained in Effective Data Analysis

A binary variable is a variable with exactly two possible categories or values.

A binary feature represents exactly two categories or values, commonly encoded as 0 and 1. In modeling, it can capture a meaningful condition such as whether a day is a weekday. section 9.2.1

Use binary features to simplify categorical information when the distinction supports the modeling question.

  • Dummy-code categorical variables by creating indicator features whose value is 1 when a category is present and 0 otherwise. section 9.2.1
  • Replace several day-of-week indicators with one weekday feature when weekdays show similar behavior and weekends form the useful contrast. section 9.2.1
  • Check correlations and weigh predictive value against added model complexity before keeping a derived feature. section 9.2.1
rats_weather["weekday"] = (rats_weather["dow"]<5).astype(int)     #1
rats_weather[
    ["high_temp", "wind_speed", "weekday", "rat_sightings"]
].corr().round(2)     #2

Inspect the binary weekday calculation and its correlations with temperature, wind speed, and rat sightings. section 9.2.1

How Effective Data Analysis covers it

How deep it goes
Explains encoding, dummy-variable alternatives, correlation checks, and complexity tradeoffs, but stops short of model fitting.
Examples
Uses New York City rat sightings, day-of-week indicators, and a weekday variable encoded as 0 or 1.
What you can do after
Build it from scratch by encoding a two-category condition and evaluating its relationship with an outcome.
How it connects
Connects binary features to categorical variables, dummy coding, linear models, correlation, and feature derivation.

Also explained in

Compare how 2 books explain binary feature →

Related concepts

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