Comparing features to reference variables
In the previous recipe, Combining features with mathematical functions, we created new features by applying mathematical or statistical functions, such as the sum or the mean, to a group of variables. Some mathematical operations, however, such as subtraction or division, make more sense when performed between two features, or when considering multiple features against one reference variable. These operations are very useful to derive ratios, such as the debt-to-income ratio:
debt-to-income ratio = total debt / total income
Alternatively, we can use them for differences, for example, to calculate disposable income:
disposable income = income - total debt
In this recipe, we will learn how to create new features via subtraction or division while utilizing pandas, and then automate the procedure for multiple variables by using Feature-engine.
How to do it…
Let’s begin by loading the necessary Python libraries and...