Feature Values

A feature value is the value a feature takes for one example. If the feature is a customer’s purchase count in the last seven days, 4 is the value for one customer. The Feature entry separates the definition, which describes how a value is obtained, from the value itself, which is the result for a particular example.

Values come in two broad kinds. Numeric values are counts, amounts, or durations. Google’s Machine Learning Glossary defines categorical data as features that have a specific set of possible values, for example a traffic-light state that can be red, yellow, or green.

Turning values into model input

According to Google’s Machine Learning Crash Course on one-hot encoding, machine learning models can only manipulate floating-point numbers, so each string has to be converted. One-hot encoding represents a category as a vector with one element per category, where exactly one element is 1.0 and the rest are 0.0. Rare values can be lumped into a single out-of-vocabulary category. For a feature with a very large number of categories, such as postal codes, that page recommends embeddings or hashing instead of one-hot vectors.

Numeric values often need scaling. Google’s Machine Learning Crash Course on normalization lists faster convergence and better predictions among the reasons to scale features with different ranges, and describes four techniques: linear scaling, Z-score scaling, log scaling, and clipping. The choice depends on the distribution of the values.

Missing values

scikit-learn’s guide to missing values notes that real datasets often contain missing values encoded as blanks, NaNs, or other placeholders, and that its estimators assume all values are numerical and meaningful. Discarding every row with a gap loses data, so a common alternative is imputation, which infers a value from the known part of the data with a mean, median, most frequent value, or constant. A missing-indicator column records which values were missing and is useful together with imputation. A code such as −1 has to be declared as missing, as scikit-learn’s missing_values parameter allows, or it will be read as a real value.

A worked example

The values and statistics are hypothetical. One customer has these feature values. The training data has a mean of 2.0 and a standard deviation of 1.5 purchases, and a median of 12 days since the last login.

FeatureRaw valueModel input
purchases in 7 days41.33 (Z-score: (4 − 2.0) / 1.5)
plan, one of free, plus, propro0, 0, 1 (one-hot)
days since last loginmissing12 (median), plus an indicator set to 1

Keep the meaning stable

The mean, the standard deviation, the category list, and the median in this example are part of the transformation. If training and prediction use different ones, or count the feature differently, the same name carries a different meaning. The Feature entry lists the things to align across training and serving: definitions, units, missing-value handling, and transformation versions. A Feature Store can help manage feature data, but it does not decide what the correct definition is.

References:


Discover more from Insightful Data Lab

Subscribe to get the latest posts sent to your email.

Similar Posts

Questions, corrections, or additional insights?

This site uses Akismet to reduce spam. Learn how your comment data is processed.