Transformations
In this section, we will consider three transformations:
- Log transformation
- Square root transformation
- Cube root transformation
First, we will import the numpy
package to create a random sample drawn from a Beta distribution. The documentation on Beta distributions can be found here:
https://numpy.org/doc/stable/reference/random/generated/numpy.random.beta.html
The sample, df
, has 10,000 values. We also use matplotlib.pyplot
to create different histogram plots. Second, we transform the original data by using a log transformation, square root transformation, and cube root transformation, and we draw four histograms:
import numpy as np import matplotlib.pyplot as plt np.random.seed(42) # for reproducible purpose # create a random data df = np.random.beta(a=1, b=10, size = 10000) df_log = np.log(df) #log transformation df_sqrt = np.sqrt(df) # Square Root transformation df_cbrt = np.cbrt(df) # Cube Root transformation plt.figure(figsize ...