Target Transformation

Target Transformation is similar to transformation as it is used to change the shape of the distribution of target variable. Target must be transformed when linear algorithms such as Linear Regression or Linear Discriminant Analysis are used for modeling. This can be achieved in PyCaret using transform_target parameter within setup. There are two methods supported for target transformation ‘box-cox’ and ‘yeo-johnson’ that can be defined using transform_target_method parameter within setup.


Parameters in setup

transform_target: bool, default = False
When set to True, target variable is transformed using the method defined in transform_target_method param. Target transformation is applied separately from feature transformations.

transform_target_method: string, default = ‘box-cox’
‘Box-cox’ and ‘yeo-johnson’ methods are supported. Box-Cox requires input data to be strictly positive, while Yeo-Johnson supports both positive or negative data.When transform_target_method is ‘box-cox’ and target variable contains negative values, method is internally forced to ‘yeo-johnson’ to avoid exceptions.


How to use?


# Importing dataset
from pycaret.datasets import get_data
diamond = get_data('diamond')

# Importing module and initializing setup
from pycaret.regression import *
reg1 = setup(data = diamond, target = 'Price', transform_target = True)


Try this next


Was this page helpful?

Send feedback