target_imputer ========================================================================== .. py:module:: evalml.pipelines.components.transformers.imputers.target_imputer .. autoapi-nested-parse:: Component that imputes missing target data according to a specified imputation strategy. Module Contents --------------- Classes Summary ~~~~~~~~~~~~~~~ .. autoapisummary:: evalml.pipelines.components.transformers.imputers.target_imputer.TargetImputer evalml.pipelines.components.transformers.imputers.target_imputer.TargetImputerMeta Contents ~~~~~~~~~~~~~~~~~~~ .. py:class:: TargetImputer(impute_strategy='most_frequent', fill_value=None, random_seed=0, **kwargs) Imputes missing target data according to a specified imputation strategy. :param impute_strategy: Impute strategy to use. Valid values include "mean", "median", "most_frequent", "constant" for numerical data, and "most_frequent", "constant" for object data types. Defaults to "most_frequent". :type impute_strategy: string :param fill_value: When impute_strategy == "constant", fill_value is used to replace missing data. Defaults to None which uses 0 when imputing numerical data and "missing_value" for strings or object data types. :type fill_value: string :param random_seed: Seed for the random number generator. Defaults to 0. :type random_seed: int **Attributes** .. list-table:: :widths: 15 85 :header-rows: 0 * - **hyperparameter_ranges** - { "impute_strategy": ["mean", "median", "most_frequent"]} * - **modifies_features** - False * - **modifies_target** - True * - **name** - Target Imputer * - **training_only** - False **Methods** .. autoapisummary:: :nosignatures: evalml.pipelines.components.transformers.imputers.target_imputer.TargetImputer.clone evalml.pipelines.components.transformers.imputers.target_imputer.TargetImputer.default_parameters evalml.pipelines.components.transformers.imputers.target_imputer.TargetImputer.describe evalml.pipelines.components.transformers.imputers.target_imputer.TargetImputer.fit evalml.pipelines.components.transformers.imputers.target_imputer.TargetImputer.fit_transform evalml.pipelines.components.transformers.imputers.target_imputer.TargetImputer.load evalml.pipelines.components.transformers.imputers.target_imputer.TargetImputer.needs_fitting evalml.pipelines.components.transformers.imputers.target_imputer.TargetImputer.parameters evalml.pipelines.components.transformers.imputers.target_imputer.TargetImputer.save evalml.pipelines.components.transformers.imputers.target_imputer.TargetImputer.transform evalml.pipelines.components.transformers.imputers.target_imputer.TargetImputer.update_parameters .. py:method:: clone(self) Constructs a new component with the same parameters and random state. :returns: A new instance of this component with identical parameters and random state. .. py:method:: default_parameters(cls) Returns the default parameters for this component. Our convention is that Component.default_parameters == Component().parameters. :returns: Default parameters for this component. :rtype: dict .. py:method:: describe(self, print_name=False, return_dict=False) Describe a component and its parameters. :param print_name: whether to print name of component :type print_name: bool, optional :param return_dict: whether to return description as dictionary in the format {"name": name, "parameters": parameters} :type return_dict: bool, optional :returns: Returns dictionary if return_dict is True, else None. :rtype: None or dict .. py:method:: fit(self, X, y) Fits imputer to target data. 'None' values are converted to np.nan before imputation and are treated as the same. :param X: The input training data of shape [n_samples, n_features]. Ignored. :type X: pd.DataFrame or np.ndarray :param y: The target training data of length [n_samples]. :type y: pd.Series, optional :returns: self :raises TypeError: If target is filled with all null values. .. py:method:: fit_transform(self, X, y) Fits on and transforms the input target data. :param X: Features. Ignored. :type X: pd.DataFrame :param y: Target data to impute. :type y: pd.Series :returns: The original X, transformed y :rtype: (pd.DataFrame, pd.Series) .. py:method:: load(file_path) :staticmethod: Loads component at file path. :param file_path: Location to load file. :type file_path: str :returns: ComponentBase object .. py:method:: needs_fitting(self) Returns boolean determining if component needs fitting before calling predict, predict_proba, transform, or feature_importances. This can be overridden to False for components that do not need to be fit or whose fit methods do nothing. :returns: True. .. py:method:: parameters(self) :property: Returns the parameters which were used to initialize the component. .. py:method:: save(self, file_path, pickle_protocol=cloudpickle.DEFAULT_PROTOCOL) Saves component at file path. :param file_path: Location to save file. :type file_path: str :param pickle_protocol: The pickle data stream format. :type pickle_protocol: int .. py:method:: transform(self, X, y) Transforms input target data by imputing missing values. 'None' and np.nan values are treated as the same. :param X: Features. Ignored. :type X: pd.DataFrame :param y: Target data to impute. :type y: pd.Series :returns: The original X, transformed y :rtype: (pd.DataFrame, pd.Series) .. py:method:: update_parameters(self, update_dict, reset_fit=True) Updates the parameter dictionary of the component. :param update_dict: A dict of parameters to update. :type update_dict: dict :param reset_fit: If True, will set `_is_fitted` to False. :type reset_fit: bool, optional .. py:class:: TargetImputerMeta A version of the ComponentBaseMeta class which handles when input features is None. **Attributes** .. list-table:: :widths: 15 85 :header-rows: 0 * - **FIT_METHODS** - ['fit', 'fit_transform'] * - **METHODS_TO_CHECK** - ['predict', 'predict_proba', 'transform', 'inverse_transform', 'get_trend_dataframe'] * - **PROPERTIES_TO_CHECK** - ['feature_importance'] **Methods** .. autoapisummary:: :nosignatures: evalml.pipelines.components.transformers.imputers.target_imputer.TargetImputerMeta.check_for_fit evalml.pipelines.components.transformers.imputers.target_imputer.TargetImputerMeta.register evalml.pipelines.components.transformers.imputers.target_imputer.TargetImputerMeta.set_fit .. py:method:: check_for_fit(cls, method) :classmethod: `check_for_fit` wraps a method that validates if `self._is_fitted` is `True`. :param method: Method to wrap. :type method: callable :raises ComponentNotYetFittedError: If component is not fitted. :returns: The wrapped input method. .. py:method:: register(cls, subclass) Register a virtual subclass of an ABC. Returns the subclass, to allow usage as a class decorator. .. py:method:: set_fit(cls, method) :classmethod: Wrapper for the fit method.