Transforming variables with the reciprocal function
The reciprocal function is defined as 1/x. The reciprocal transformation is often useful when we have ratios – that is, values resulting from the division of two variables. Examples of this are population density – that is, people per area – and, as we will see in this recipe, house occupancy – that is, the number of occupants per house.
The reciprocal transformation is not defined for the value 0, and although defined for negative values, it is mainly useful for transforming positive variables.
In this recipe, we will implement the reciprocal transformation using NumPy, scikit-learn, and Feature-engine, and compare its effect on variable distribution using histograms and a Q-Q plot.
How to do it...
Let’s begin by importing the libraries and getting the dataset ready:
- Import the required Python libraries and data:
import numpy as np import pandas as pd import matplotlib.pyplot...