Skip to content
Machine Learning

What is the difference between a dense and a sparse feature?

A dense feature is one in which most values are non-zero in contrast with a sparse one where most values are zeros or empty.

datasciencetrivia.com

Card 1 of 259. Answer: A dense feature is one in which most values are non-zero in contrast with a sparse one where most values are zeros or empty.

Created by santiviquez

About · Quizzes · History of AI · To suggest new questions or report an error send me a dm.

The longer answer

A dense feature has a meaningful, mostly non-zero value for almost every row, like age, price or a 300-dimensional word embedding. A sparse feature is zero or missing for most rows, like a one-hot encoded city column or a bag-of-words vector where each document uses a few hundred words out of a vocabulary of 50,000.

The difference changes how you store and model the data. Sparse matrices are kept in formats such as CSR that only record the non-zero entries, so a million-column one-hot matrix still fits in memory. Linear models and gradient-boosted trees handle sparse inputs well; distance-based methods like KNN and k-means struggle, because in a sparse space most points look almost equally far apart.

A common move in interviews and in practice is to turn sparse features into dense ones: embeddings compress a high-cardinality category into a short dense vector, and techniques like truncated SVD do the same for text.

All questions