How it works...
In this recipe, we applied the square and cube root transformations to variables in the Boston House Prices dataset using NumPy and scikit-learn.
To apply the square or cube root transformations with NumPy, we created a copy of the original dataframe with pandas copy() and then used sqrt() or cbrt() on a slice of the dataset with the variables to be transformed. This procedure returned a pandas dataframe with the original variables, while LSTAT, NOX, DIS, and RM were transformed with the square root.
To apply the square root transformation with scikit-learn, we used FunctionTransformer(), which applies a user-defined function – in this case, np.sqrt – to a dataset and returns the result in a NumPy array. The transform() method ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access