🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Machine Learning Notes
Topic #76

Numerical Features

Numerical features are the easiest data type to feed a model directly — but "already a number" doesn't mean "already in the right form." Binning, transforming and scaling numeric features correctly often matters as much as any encoding decision for categorical data.

Common Numerical Feature Engineering Techniques

TechniqueWhat It DoesWhen to Use
Binning / discretizationConverts a continuous value into ranges (e.g. age → "18-25", "26-35", ...)When the relationship to the target is non-linear but roughly step-wise
Log / power transformsCompresses right-skewed distributions closer to symmetricIncome, prices, counts — see Feature Transformation
ScalingRescales a feature's rangeDistance- and gradient-based models
Ratios and ratesCombines two numeric features into one more meaningful signal"income / household_size" often predicts more than either alone

Binning — A Worked Example

import pandas as pd

df = pd.DataFrame({"age": [17, 22, 29, 35, 44, 58, 65]})

df["age_group"] = pd.cut(
    df["age"],
    bins=[0, 18, 30, 45, 60, 100],
    labels=["under_18", "18_30", "30_45", "45_60", "60_plus"]
)
print(df)

Binning trades away some precision (35 and 44 both fall in "30_45") in exchange for letting a linear model capture a non-linear age effect — e.g. if risk is elevated specifically for both very young and very old customers, a single linear "age" coefficient can't represent that U-shape, but a set of age-group dummy variables can.

Ratios — Often More Predictive Than Either Raw Feature

df["debt_to_income"] = df["total_debt"] / df["annual_income"]
df["price_per_sqft"] = df["price"] / df["size_sqft"]

A ratio like debt-to-income is frequently far more predictive for credit risk than either "debt" or "income" alone — it directly encodes the relationship a domain expert would actually reason about, instead of leaving the model to rediscover that relationship on its own from two separate columns.

Practical Use Cases

  • Converting a continuous feature with a non-linear target relationship into bins a linear model can use
  • Building domain-informed ratios (price per unit, rate per time period) that carry more signal than raw values
  • Reducing the influence of extreme values through binning, as an alternative to outlier removal

Common Mistakes

  • Binning a feature that already has a genuinely linear relationship with the target — this throws away precision for no benefit.
  • Choosing bin edges arbitrarily instead of based on domain knowledge or the data's actual distribution (e.g. quantile-based bins via pd.qcut).
  • Creating a ratio with a denominator that can be zero, without handling the resulting division error.

Interview Relevance

Q: "When would you bin a numeric feature instead of leaving it continuous?" When you suspect a non-linear, step-wise relationship with the target that a linear model can't otherwise capture, or when you specifically want to reduce sensitivity to noise/outliers at the cost of some precision.

Practice Question

You have "num_dependents" and "annual_income" columns for a loan approval model. Propose one ratio feature that would likely help a linear model more than the two raw columns alone.

Want to go beyond the notes?

Join CodingNow 2.0's Machine Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Numerical Features – FAQs

Quick answers about learning Numerical Features in Machine Learning.

This free note from CodingNow 2.0 explains Numerical Features in Machine Learning — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Machine Learning topic on CodingNow 2.0, including Numerical Features, is 100% free with no signup required.
With focused practice, most students grasp Numerical Features in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now