Let's get started by importing Matplotlib and Numpy
Let's get started by creating a reproducible random number generator. This ensures the result is the same no matter how many times we generate the random data.
The next step is to generate some random data where it makes sense to apply a logarithmic transformation to make it easier to see the relationship between the variables.
In this case, we're going to generate data that violates the homoscedasticity assumption of ordinary linear regression. This is just statistical jargon that means that the variability of the y variable is not constant for all the values of x. In this case, the variability of y increases as the value of x increases.
Let's say the horizontal scale is logarithmic now:
And what if the vertical scale is logarithmic?
Let's use a logarithmic scale for both axes now:
The relationship between the variables is linear in this log-transformed space and the variability of y looks constant. So cool!