July 2019
Beginner to intermediate
740 pages
16h 52m
English
What if, rather than scaling our data or encoding it, we want to run a mathematical operation, like taking the square root or the logarithm? The preprocessing module also has some classes for this. While there are a few that do a specific transformation, like the QuantileTransformer, we will focus our attention on the FunctionTransformer, which lets us provide an arbitrary function to use:
>>> from sklearn.preprocessing import FunctionTransformer>>> FunctionTransformer(... np.abs, validate=True... ).fit_transform(X_train.dropna())array([[0.073 , 2.6 , 1.6 ],
...,
[0.249 , 4.62 , 2.99 ]])
Here, we took the absolute value of every number. Notice the validate=True argument; the FunctionTransformer knows that scikit-learn ...
Read now
Unlock full access