Simple metric transformations¶
Unit for a Box-Cox transformation of the pandas data. |
|
Unit for a logarithmic transformation of the pandas data. |
- class ambrosia.preprocessing.BoxCoxTransformer[source]¶
Unit for a Box-Cox transformation of the pandas data.
A Box Cox transformation helps to transform non-normal dependent variables into a normal shape. All variables values must be positive.
Optimal transformation lambdas are selected automatically during the transformer fit process.
- Attributes:
- column_namesList
Names of column which will be selected for the transformation.
- lambda_np.ndarray
Array of parameters using during the transformation of the selected columns.
- fittedbool
Fit flag.
Examples
>>> boxcox = BoxCoxTransformer() >>> boxcox.fit(dataframe, ['column1', 'column2']) >>> boxcox.transform(dataframe, inplace=True)
- fit(dataframe, column_names)[source]¶
Fit to calculate transformation parameters for the selected columns.
- Parameters:
- dataframepd.DataFrame
Dataframe to calculate optimal transformation parameters.
- column_namesColumnNamesType
One or number of columns in the dataframe.
- Returns:
- selfobject
Instance object.
- transform(dataframe, inplace=False)[source]¶
Apply Box-Cox transformation for the data.
- Parameters:
- dataframepd.DataFrame
Dataframe to transform.
- inplacebool, default:
False If
Truetransforms the given dataframe, otherwise copy and returns an another one.
- Returns:
- dfUnion[pd.DataFrame, None]
Transformed dataframe or None
- fit_transform(dataframe, column_names, inplace=False)[source]¶
Fit transformer parameters using given dataframe and transform it.
- Parameters:
- dataframepd.DataFrame
Dataframe for calculation of optimal parameters and further transformation.
- column_namesColumnNamesType
One or number of columns in the dataframe.
- inplacebool, default:
False If
Truetransforms the given dataframe, otherwise copy and returns an another one.
- Returns:
- dfUnion[pd.DataFrame, None]
Transformed dataframe or None
- store_params(store_path)¶
- Parameters:
- store_pathPath
Path where parameters will be stored in a json format.
- load_params(load_path)¶
- Parameters:
- load_pathPath
Path to json file with parameters.
- class ambrosia.preprocessing.LogTransformer[source]¶
Unit for a logarithmic transformation of the pandas data.
A logarithmic transformation helps to transform some metrics distributions into a more normal shape and reduce the variance. All metrics values must be positive.
- Attributes:
- column_namesList
Names of column which will be selected for the transformation.
- fittedbool
Fit flag.
Examples
>>> log = LogTransformer() >>> log.fit(dataframe, ['column1', 'column2']) >>> log.transform(dataframe, inplace=True)
- fit(dataframe, column_names)[source]¶
Fit names of the selected columns.
- Parameters:
- dataframepd.DataFrame
Dataframe with metrics.
- column_namesColumnNamesType
One or number of columns in the dataframe.
- Returns:
- selfobject
Instance object.
- transform(dataframe, inplace=False)[source]¶
Apply log transformation for the data.
- Parameters:
- dataframepd.DataFrame
Dataframe to transform.
- inplacebool, default:
False If
Truetransforms the given dataframe, otherwise copy and returns an another one.
- Returns:
- dfUnion[pd.DataFrame, None]
Transformed dataframe or None
- fit_transform(dataframe, column_names, inplace=False)[source]¶
Fit transformer parameters using given dataframe and transform it.
Only column names are fittable.
- Parameters:
- dataframepd.DataFrame
Dataframe to transform.
- column_namesColumnNamesType
One or number of columns in the dataframe.
- inplacebool, default:
False If
Truetransforms the given dataframe, otherwise copy and returns an another one.
- Returns:
- dfUnion[pd.DataFrame, None]
Transformed dataframe or None
- store_params(store_path)¶
- Parameters:
- store_pathPath
Path where parameters will be stored in a json format.
- load_params(load_path)¶
- Parameters:
- load_pathPath
Path to json file with parameters.