class_docstr: Season-Trend decomposition using LOESS for multiple seasonalities.
  
  Direct interface for ``statsmodels.tsa.seasonal.MSTL``.
  ``MSTL`` can be used to perform deseasonalization or decomposition:
  
  `fit` stores the decomposed values in self.trend_, self.seasonal_, and self.resid_.
  If `return_components=False`, then `transform` returns a pd.Series of the
  deseasonalized values. The seasonal and residual components can be found in
  self.trend_ and self.resid_.
  If `return_components=True`, then `transform` returns the transformed series, as
  well as three components as variables in the returned multivariate series
  (DataFrame cols)
      "transformed" - the transformed series
      "seasonal" - the seasonal component(s), summed up if multiple
      "trend" - the trend component
      "resid" - the residuals after de-trending, de-seasonalizing
  
  ``MSTL`` performs ``inverse_transform`` by summing any components,
  and can be used for pipelining in a ``TransformedTargetForecaster``.
  
  Important: for separate forecasts of trend and seasonalities, and an
  inverse transform that respects seasonality, ensure
  that ``return_components=True`` is set, otherwise the inverse will just
  return the trend component.
  
  Parameters
  ----------
  endog : array_like
      Data to be decomposed. Must be squeezable to 1-d.
  periods : {int, array_like, None}, optional
      Periodicity of the seasonal components. If None and endog is a pandas Series or
      DataFrame, attempts to determine from endog. If endog is a ndarray, periods
      must be provided.
  windows : {int, array_like, None}, optional
      Length of the seasonal smoothers for each corresponding period. Must be an odd
      integer, and should normally be >= 7 (default). If None then default values
      determined using 7 + 4 * np.arange(1, n + 1, 1) where n is number of seasonal
      components.
  lmbda : {float, str, None}, optional
      The lambda parameter for the Box-Cox transform to be applied to endog prior to
      decomposition. If None, no transform is applied. If `auto`, a value will be
      estimated that maximizes the log-likelihood function.
  iterate : int, optional
      Number of iterations to use to refine the seasonal component.
  stl_kwargs : dict, optional
      Arguments to pass to STL.
  return_components : bool, default=False
      if False, will return only the MSTL transformed series
      if True, will return the transformed series, as well as three components
          as variables in the returned multivariate series (DataFrame cols)
          "transformed" - the transformed series
          "seasonal" - the seasonal component(s), summed up if multiple
          "trend" - the trend component
          "resid" - the residuals after de-trending, de-seasonalizing
  
  Attributes
  ----------
  trend_ : pd.Series
      Trend component of series seen in fit.
  seasonal_ : pd.Series or list of pd.Series
      If `periods` is a single value, this contains the seasonal component of the
      series observed during fitting.
      If `periods` is a list of values, this can contain multiple pd.Series, each
      corresponding to a different period.
  resid_ : pd.Series
      Residuals component of series seen in fit.
  
  References
  ----------
  [1] https://www.statsmodels.org/dev/generated/statsmodels.tsa.seasonal.MSTL.html
  
  Examples
  --------
  >>> import matplotlib.pyplot as plt  # doctest: +SKIP
  >>> from sktime.datasets import load_airline
  >>> from sktime.transformations.series.detrend.mstl import MSTL
  >>> y = load_airline()
  >>> y.index = y.index.to_timestamp()
  >>> mstl = MSTL(return_components=True)  # doctest: +SKIP
  >>> fitted = mstl.fit(y)  # doctest: +SKIP
  >>> res = fitted.transform(y)  # doctest: +SKIP
  >>> res.plot()  # doctest: +SKIP
  >>> plt.tight_layout()  # doctest: +SKIP
  >>> plt.show()  # doctest: +SKIP
class_docstr_tok: ["Season-Trend","decomposition","using","LOESS","for","multiple","seasonalities",".","Direct","interface","for","``","statsmodels.tsa.seasonal.MSTL","``",".","``","MSTL","``","can","be","used","to","perform","deseasonalization","or","decomposition",":","`","fit","`","stores","the","decomposed","values","in","self.trend_",",","self.seasonal_",",","and","self.resid_",".","If","`","return_components=False","`",",","then","`","transform","`","returns","a","pd.Series","of","the","deseasonalized","values",".","The","seasonal","and","residual","components","can","be","found","in","self.trend_","and","self.resid_",".","If","`","return_components=True","`",",","then","`","transform","`","returns","the","transformed","series",",","as","well","as","three","components","as","variables","in","the","returned","multivariate","series","(","DataFrame","cols",")","``","transformed","''","-","the","transformed","series","``","seasonal","''","-","the","seasonal","component","(","s",")",",","summed","up","if","multiple","``","trend","''","-","the","trend","component","``","resid","''","-","the","residuals","after","de-trending",",","de-seasonalizing","``","MSTL","``","performs","``","inverse_transform","``","by","summing","any","components",",","and","can","be","used","for","pipelining","in","a","``","TransformedTargetForecaster","``",".","Important",":","for","separate","forecasts","of","trend","and","seasonalities",",","and","an","inverse","transform","that","respects","seasonality",",","ensure","that","``","return_components=True","``","is","set",",","otherwise","the","inverse","will","just","return","the","trend","component",".","Parameters","--","--","--","--","--","endog",":","array_like","Data","to","be","decomposed",".","Must","be","squeezable","to","1-d.","periods",":","{","int",",","array_like",",","None","}",",","optional","Periodicity","of","the","seasonal","components",".","If","None","and","endog","is","a","pandas","Series","or","DataFrame",",","attempts","to","determine","from","endog",".","If","endog","is","a","ndarray",",","periods","must","be","provided",".","windows",":","{","int",",","array_like",",","None","}",",","optional","Length","of","the","seasonal","smoothers","for","each","corresponding","period",".","Must","be","an","odd","integer",",","and","should","normally","be",">","=","7","(","default",")",".","If","None","then","default","values","determined","using","7","+","4","*","np.arange","(","1",",","n","+","1",",","1",")","where","n","is","number","of","seasonal","components",".","lmbda",":","{","float",",","str",",","None","}",",","optional","The","lambda","parameter","for","the","Box-Cox","transform","to","be","applied","to","endog","prior","to","decomposition",".","If","None",",","no","transform","is","applied",".","If","`","auto","`",",","a","value","will","be","estimated","that","maximizes","the","log-likelihood","function",".","iterate",":","int",",","optional","Number","of","iterations","to","use","to","refine","the","seasonal","component",".","stl_kwargs",":","dict",",","optional","Arguments","to","pass","to","STL",".","return_components",":","bool",",","default=False","if","False",",","will","return","only","the","MSTL","transformed","series","if","True",",","will","return","the","transformed","series",",","as","well","as","three","components","as","variables","in","the","returned","multivariate","series","(","DataFrame","cols",")","``","transformed","''","-","the","transformed","series","``","seasonal","''","-","the","seasonal","component","(","s",")",",","summed","up","if","multiple","``","trend","''","-","the","trend","component","``","resid","''","-","the","residuals","after","de-trending",",","de-seasonalizing","Attributes","--","--","--","--","--","trend_",":","pd.Series","Trend","component","of","series","seen","in","fit",".","seasonal_",":","pd.Series","or","list","of","pd.Series","If","`","periods","`","is","a","single","value",",","this","contains","the","seasonal","component","of","the","series","observed","during","fitting",".","If","`","periods","`","is","a","list","of","values",",","this","can","contain","multiple","pd.Series",",","each","corresponding","to","a","different","period",".","resid_",":","pd.Series","Residuals","component","of","series","seen","in","fit",".","References","--","--","--","--","--","[","1","]","https",":","\/\/www.statsmodels.org\/dev\/generated\/statsmodels.tsa.seasonal.MSTL.html","Examples","--","--","--","--",">",">",">","import","matplotlib.pyplot","as","plt","#","doctest",":","+SKIP",">",">",">","from","sktime.datasets","import","load_airline",">",">",">","from","sktime.transformations.series.detrend.mstl","import","MSTL",">",">",">","y","=","load_airline","(",")",">",">",">","y.index","=","y.index.to_timestamp","(",")",">",">",">","mstl","=","MSTL","(","return_components=True",")","#","doctest",":","+SKIP",">",">",">","fitted","=","mstl.fit","(","y",")","#","doctest",":","+SKIP",">",">",">","res","=","fitted.transform","(","y",")","#","doctest",":","+SKIP",">",">",">","res.plot","(",")","#","doctest",":","+SKIP",">",">",">","plt.tight_layout","(",")","#","doctest",":","+SKIP",">",">",">","plt.show","(",")","#","doctest",":","+SKIP"]
code: def _make_return_object(self, X, mstl):
      if len(mstl.seasonal.shape) > 1:
          seasonal = mstl.seasonal.sum(axis=1)
      else:
          seasonal = mstl.seasonal
      # deseasonalize only
      transformed = pd.Series(X.values - seasonal, index=X.index)
      # transformed = pd.Series(X.values - stl.seasonal - stl.trend, index=X.index)
  
      if self.return_components:
          resid = pd.Series(mstl.resid, index=X.index)
          trend = pd.Series(mstl.trend, index=X.index)
  
          ret = {
              "transformed": transformed,
              "trend": trend,
              "resid": resid,
          }
  
          for column_name, column_data in mstl.seasonal.iteritems():
              ret[column_name] = column_data
  
          ret = pd.DataFrame(ret)
      else:
          ret = transformed
  
      return ret
  
file_path: sktime/sktime/transformations/series/detrend/mstl.py
imports: from typing import Dict, Optional, Sequence, Union
  import pandas
  from sktime.transformations.base import BaseTransformer
label_desc: Use image node_id 5 for calling the MSTL obj's underlying member method code with example usage: obj._make_return_object(X, mstl) and returns: ret