A logarithmic transformation replaces each value with its logarithm, compressing differences across several orders of magnitude and helping reduce right skewness. Use it when preparing variables for linear regression, but interpret the fitted relationship on the transformed scale rather than automatically on the original scale. section 4.1.3
Apply a logarithmic scale when:
- The data spans several orders of magnitude and its range needs compression. section 4.1.3
- The distribution is right-skewed and transformation may help it approach normality. section 4.1.3
- A linear model requires transformed data to better meet its assumptions, while alternative nonlinear models remain worth considering. section 4.1.3
Transforming a regression variable
For a variable x in a pandas data frame df, apply df['x'] = np.log(df['x']) or df['x'] = np.log10(df['x']). The resulting regression describes associations using the transformed x values. Compare the transformed model with alternatives and inspect the influence of outliers rather than treating improved fit alone as sufficient evidence. section 4.1.3
df['x'] = np.log(df['x'])
Use the compact NumPy listing to apply a natural-log transformation directly to a data-frame column. section 4.1.3
Logarithmic scales also describe Benford distributions: leading digits are not equally likely, with 1 occurring about 30% of the time and 9 occurring below 5%. section 12.1
Computing a Benford distribution
For digits d from 1 through 9, compute round(np.log10(1 + (1 / d)), 3). The resulting values begin 0.301 for 1 and 0.046 for 9, and sum to 1.0. Plotting these probabilities distinguishes the logarithmic pattern from uniform or random distributions. section 12.1 section 12.3.3


