Data distribution describes how values are spread across their full range—whether they cluster near a bell-shaped center, spread evenly, or lean heavily toward one side. Inspecting distributions early prevents feeding distorted features into linear or distance-based models.
Histograms and summary quantiles reveal distribution shape quickly before you choose scaling or transformation steps.
[low, high] has equal probability (like rolling a fair die or random.uniform(0, 10)).random.gauss(mu, sigma)).import random
import statistics
random.seed(7)
uniform_vals = [round(random.uniform(0, 100), 2) for _ in range(500)]
normal_vals = [round(random.gauss(50, 10), 2) for _ in range(500)]
print("Uniform stdev:", round(statistics.stdev(uniform_vals), 2))
print("Normal stdev:", round(statistics.stdev(normal_vals), 2))
When a positive feature like revenue has extreme large values, applying a log transform (math.log1p(x) or np.log1p(x)) compresses the long tail and often improves linear regression accuracy.
math.log(x) when values include 0: log(0) is undefined and raises ValueError; use log1p(x) (log(1 + x)) instead.log1p(price), apply expm1(pred) before reporting predicted prices.Plot a histogram with matplotlib.pyplot.hist(values, bins=30) or compare the mean against the median—when mean >> median, the data is right-skewed.
No. Tree-based models like Random Forests and XGBoost split on rank order, so skewness does not hurt them.
random.gauss(mu=50, sigma=10) generate?It generates floating-point numbers drawn from a normal distribution centered at 50 with a standard deviation of 10.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.