liveBook · Manning

Sparsity

As explained in Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI

Sparsity is a property of a data representation in which many entries or coefficients are zero or empty.

Sparsity describes a representation dominated by zeros or empty values. In tabular machine learning, one-hot encoding can create many binary columns; when most entries are zero, learning may become more difficult, especially for neural networks and online algorithms. section 4.2.1

The practical trigger is often categorical cardinality. Encoding a feature with more than 20 unique values can produce excessive columns and a sparse dataset, so separate low-cardinality features from high-cardinality ones before encoding. section 4.2.1

Categorical features in a listings dataset

A listings dataset contains five neighbourhood groups, 221 neighbourhoods, and three room types. Treat neighbourhood_group and room_type as low-cardinality categorical features, while neighbourhood is high-cardinality and may require another encoding strategy rather than direct one-hot encoding. section 4.2.1

Use sparsity as a modeling and preprocessing signal:

  • Measure sparsity through the percentage of zero values among numeric entries. section 4.3.6
  • Expect increasing memory and computational pressure as the number of binary features grows. section 4.3.6
  • Consider online learning or deep learning earlier when datasets are very sparse, particularly at large scale. section 4.3.6
  • Use target encoding for categorical features with too many unique values when direct one-hot encoding becomes excessive. section 4.2.1

How Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI covers it

How deep it goes
Defines sparsity, identifies its causes and consequences, and stops short of detailed storage formats or mathematical derivations.
Examples
Uses NYC listings features to contrast low-cardinality room types and neighbourhood groups with high-cardinality neighbourhood values.
What it assumes
Assumes familiarity with tabular features and one-hot encoding while separating low- and high-cardinality cases in practice.
What you can do after
Apply it via pandas preprocessing and algorithm comparison to recognize costly encodings and choose alternatives.
How it connects
Connects sparsity with one-hot encoding, categorical features, cardinality, online learning, and deep learning.

Also explained in

Compare how 4 books explain sparsity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI. The section links point to the parts of the book it draws on.