Answer

How do you normalize data to a 0-1 range?

Inspired by a question on Cross Validated ·

normalizationdescriptive statistics

The short answer

To rescale a value x into the range [0, 1], subtract the minimum of your data and divide by the range (max minus min): (x - min) / (max - min). The smallest value in the data becomes 0, the largest becomes 1, and every other value keeps its relative position between them. This is called min-max normalization, and it is a different technique from standardizing to z-scores.

The formula

Min-max normalization maps every value in a data set onto a fixed scale, usually 0 to 1, while preserving the order and relative spacing of the values. For a value x drawn from data with minimum min and maximum max, the rescaled value is (x - min) / (max - min).

Plugging in the minimum itself gives (min - min) / (max - min) = 0, and plugging in the maximum gives (max - min) / (max - min) = 1. Everything else lands proportionally in between, so a value that sits 30% of the way from the minimum to the maximum still sits at 0.3 after rescaling.

A worked example

Take five values with a minimum of -23.89 and a maximum of 7.5499067: -23.89, -10.2, -1.5, 5.6878, and 7.5499067. Applying the formula gives 0, 0.4354, 0.7122, 0.9408, and 1 (rounded to four decimals). The most negative value became 0, the largest became 1, and the others fell in order between them.

If you already know the minimum and maximum of the full data set, you can rescale a single new value directly without recomputing anything: with a minimum of -23.89 and a maximum of 7.5499067, the value 5.6878 rescales to about 0.9408, matching its position in the list above.

Scaling to a range other than 0-1

The same idea extends to any target range [a, b]: compute the 0-1 version first, then stretch it with a + (x - min) / (max - min) * (b - a). For the five values above, rescaling to [-1, 1] instead of [0, 1] gives -1, -0.1291, 0.4243, 0.8815, and 1.

When to use it, and when not to

Common pitfalls

See it in R

This reproduces the worked example above, extends it to an arbitrary target range, and shows how a single large outlier affects min-max scaling, z-score standardization, and robust scaling.

# A small, self-contained data set with an obvious min and max.
# (No random component here, so no seed is needed -- every number below
# is reproducible exactly as printed.)
x <- c(-23.89, -10.2, -1.5, 5.6878, 7.5499067)

min_max <- function(v, lo = min(v), hi = max(v)) {
  (v - lo) / (hi - lo)
}

round(min_max(x), 4)
# The minimum maps to 0, the maximum maps to 1, and everything
# else falls in between in the same relative position.

# The single-value case from a known min and max, without recomputing them:
min_max(5.6878, lo = -23.89, hi = 7.5499067)

# Rescaling to an arbitrary range [a, b] instead of [0, 1]:
rescale <- function(v, a, b, lo = min(v), hi = max(v)) {
  a + (v - lo) / (hi - lo) * (b - a)
}
round(rescale(x, a = -1, b = 1), 4)

# Min-max scaling is sensitive to outliers, because they set lo/hi.
# Z-scores are too: the outlier drags the mean and SD along with it.
y <- c(x, 500)  # one outlier added
round(min_max(y), 4)          # the outlier compresses everything else near 0
round(scale(y)[, 1], 4)       # the same squeeze, in standard-deviation units

# Robust scaling (median and IQR) keeps the ordinary values spread out:
round((y - median(y)) / IQR(y), 2)

Adding the outlier of 500 compresses the original five values into the narrow band 0 to 0.06 under min-max scaling. Z-scores are no better: the same five values bunch between about -0.50 and -0.35. Both are straight-line rescalings, so the five values keep exactly the same relative spacing either way; only the units differ. Robust scaling keeps them spread from -1.72 to 0.36 and leaves the outlier far out at 32.95, where it is easy to spot and deal with.

How to report min-max normalization in APA style (7th edition)

Rescaling is a data-preparation step, so it belongs in the method section rather than the results. Say which variables were rescaled, the formula, and where the minimum and maximum came from. For example:

"Each predictor was rescaled to the range 0 to 1 with min-max normalization, (x - min) / (max - min), using the minimum and maximum of the training set."

Report descriptive statistics on the original scale so readers can interpret them, and say so if any new observations fell outside the 0 to 1 range.

Related tools and guides

More answered questions

Working with your own data?

General answers only go so far. Send us your situation and we'll reply by email within two business days.

Ask your question

Written by AskStats with AI assistance. This is general information, not advice for your specific data or study. When the results matter, check your approach with a qualified statistician.