decomposer =========================================================================== .. py:module:: evalml.pipelines.components.transformers.preprocessing.decomposer .. autoapi-nested-parse:: Component that removes trends from time series and returns the decomposed components. Module Contents --------------- Classes Summary ~~~~~~~~~~~~~~~ .. autoapisummary:: evalml.pipelines.components.transformers.preprocessing.decomposer.Decomposer Contents ~~~~~~~~~~~~~~~~~~~ .. py:class:: Decomposer(component_obj=None, random_seed: int = 0, degree: int = 1, period: int = -1, seasonal_smoother: int = 7, time_index: str = None, **kwargs) Component that removes trends and seasonality from time series and returns the decomposed components. :param parameters: Dictionary of parameters to pass to component object. :type parameters: dict :param component_obj: Instance of a detrender/deseasonalizer class. :type component_obj: class :param random_seed: Seed for the random number generator. Defaults to 0. :type random_seed: int :param degree: Currently the degree of the PolynomialDecomposer, not used for STLDecomposer. :type degree: int :param period: The best guess, in units, for the period of the seasonal signal. :type period: int :param seasonal_smoother: The seasonal smoothing parameter for STLDecomposer, not used for PolynomialDecomposer. :type seasonal_smoother: int :param time_index: The column name of the feature matrix (X) that the datetime information should be pulled from. :type time_index: str **Attributes** .. list-table:: :widths: 15 85 :header-rows: 0 * - **hyperparameter_ranges** - None * - **invalid_frequencies** - [] * - **modifies_features** - False * - **modifies_target** - True * - **name** - Decomposer * - **needs_fitting** - True * - **training_only** - False **Methods** .. autoapisummary:: :nosignatures: evalml.pipelines.components.transformers.preprocessing.decomposer.Decomposer.clone evalml.pipelines.components.transformers.preprocessing.decomposer.Decomposer.default_parameters evalml.pipelines.components.transformers.preprocessing.decomposer.Decomposer.describe evalml.pipelines.components.transformers.preprocessing.decomposer.Decomposer.determine_periodicity evalml.pipelines.components.transformers.preprocessing.decomposer.Decomposer.fit evalml.pipelines.components.transformers.preprocessing.decomposer.Decomposer.fit_transform evalml.pipelines.components.transformers.preprocessing.decomposer.Decomposer.get_trend_dataframe evalml.pipelines.components.transformers.preprocessing.decomposer.Decomposer.inverse_transform evalml.pipelines.components.transformers.preprocessing.decomposer.Decomposer.is_freq_valid evalml.pipelines.components.transformers.preprocessing.decomposer.Decomposer.load evalml.pipelines.components.transformers.preprocessing.decomposer.Decomposer.parameters evalml.pipelines.components.transformers.preprocessing.decomposer.Decomposer.plot_decomposition evalml.pipelines.components.transformers.preprocessing.decomposer.Decomposer.save evalml.pipelines.components.transformers.preprocessing.decomposer.Decomposer.set_period evalml.pipelines.components.transformers.preprocessing.decomposer.Decomposer.transform evalml.pipelines.components.transformers.preprocessing.decomposer.Decomposer.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:: determine_periodicity(cls, X: pandas.DataFrame, y: pandas.Series, acf_threshold: float = 0.01, rel_max_order: int = 5) :classmethod: Function that uses autocorrelative methods to determine the likely most signficant period of the seasonal signal. :param X: The feature data of the time series problem. :type X: pandas.DataFrame :param y: The target data of a time series problem. :type y: pandas.Series :param acf_threshold: The threshold for the autocorrelation function to determine the period. Any values below the threshold are considered to be 0 and will not be considered for the period. Defaults to 0.01. :type acf_threshold: float :param rel_max_order: The order of the relative maximum to determine the period. Defaults to 5. :type rel_max_order: int :returns: The integer number of entries in time series data over which the seasonal part of the target data repeats. If the time series data is in days, then this is the number of days that it takes the target's seasonal signal to repeat. Note: the target data can contain multiple seasonal signals. This function will only return the stronger. E.g. if the target has both weekly and yearly seasonality, the function may return either "7" or "365", depending on which seasonality is more strongly autocorrelated. If no period is detected, returns None. :rtype: int .. py:method:: fit(self, X, y=None) Fits component to data. :param X: The input training data of shape [n_samples, n_features] :type X: pd.DataFrame :param y: The target training data of length [n_samples] :type y: pd.Series, optional :returns: self :raises MethodPropertyNotFoundError: If component does not have a fit method or a component_obj that implements fit. .. py:method:: fit_transform(self, X: pandas.DataFrame, y: pandas.Series = None) -> tuple[pandas.DataFrame, pandas.Series] Removes fitted trend and seasonality from target variable. :param X: Ignored. :type X: pd.DataFrame, optional :param y: Target variable to detrend and deseasonalize. :type y: pd.Series :returns: The first element are the input features returned without modification. The second element is the target variable y with the fitted trend removed. :rtype: tuple of pd.DataFrame, pd.Series .. py:method:: get_trend_dataframe(self, y: pandas.Series) :abstractmethod: Return a list of dataframes, each with 3 columns: trend, seasonality, residual. .. py:method:: inverse_transform(self, y: pandas.Series) :abstractmethod: Add the trend + seasonality back to y. .. py:method:: is_freq_valid(cls, freq: str) :classmethod: Determines if the given string represents a valid frequency for this decomposer. :param freq: A frequency to validate. See the pandas docs at https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases for options. :type freq: str :returns: boolean representing whether the frequency is valid or not. .. 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:: parameters(self) :property: Returns the parameters which were used to initialize the component. .. py:method:: plot_decomposition(self, X: pandas.DataFrame, y: pandas.Series, show: bool = False) -> tuple[matplotlib.pyplot.Figure, list] Plots the decomposition of the target signal. :param X: Input data with time series data in index. :type X: pd.DataFrame :param y: Target variable data provided as a Series for univariate problems or a DataFrame for multivariate problems. :type y: pd.Series or pd.DataFrame :param show: Whether to display the plot or not. Defaults to False. :type show: bool :returns: The figure and axes that have the decompositions plotted on them :rtype: matplotlib.pyplot.Figure, list[matplotlib.pyplot.Axes] .. 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:: set_period(self, X: pandas.DataFrame, y: pandas.Series, acf_threshold: float = 0.01, rel_max_order: int = 5) Function to set the component's seasonal period based on the target's seasonality. :param X: The feature data of the time series problem. :type X: pandas.DataFrame :param y: The target data of a time series problem. :type y: pandas.Series :param acf_threshold: The threshold for the autocorrelation function to determine the period. Any values below the threshold are considered to be 0 and will not be considered for the period. Defaults to 0.01. :type acf_threshold: float :param rel_max_order: The order of the relative maximum to determine the period. Defaults to 5. :type rel_max_order: int .. py:method:: transform(self, X, y=None) :abstractmethod: Transforms data X. :param X: Data to transform. :type X: pd.DataFrame :param y: Target data. :type y: pd.Series, optional :returns: Transformed X :rtype: pd.DataFrame :raises MethodPropertyNotFoundError: If transformer does not have a transform method or a component_obj that implements transform. .. 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