class_docstr: Conduct a KPSS test for stationarity.
  
  In econometrics, Kwiatkowski–Phillips–Schmidt–Shin (KPSS) tests are used
  for testing a null hypothesis that an observable time series is stationary
  around a deterministic trend (i.e. trend-stationary) against the
  alternative of a unit root.
  
  Parameters
  ----------
  alpha : float, optional (default=0.05)
      Level of the test
  
  null : str, optional (default='level')
      Whether to fit the linear model on the one vector, or an arange.
      If ``null`` is 'trend', a linear model is fit on an arange, if
      'level', it is fit on the one vector.
  
  lshort : bool, optional (default=True)
      Whether or not to truncate the ``l`` value in the C code.
  
  Notes
  -----
  This test is generally used indirectly via the
  :func:`pmdarima.arima.ndiffs` function, which computes the
  differencing term, ``d``.
  
  References
  ----------
  .. [1] R's tseries KPSS test source code: http://bit.ly/2eJP1IU
class_docstr_tok: ["Conduct","a","KPSS","test","for","stationarity",".","In","econometrics",",","Kwiatkowski\u2013Phillips\u2013Schmidt\u2013Shin","(","KPSS",")","tests","are","used","for","testing","a","null","hypothesis","that","an","observable","time","series","is","stationary","around","a","deterministic","trend","(","i.e",".","trend-stationary",")","against","the","alternative","of","a","unit","root",".","Parameters","--","--","--","--","--","alpha",":","float",",","optional","(","default=0.05",")","Level","of","the","test","null",":","str",",","optional","(","default='level","'",")","Whether","to","fit","the","linear","model","on","the","one","vector",",","or","an","arange",".","If","``","null","``","is","'trend","'",",","a","linear","model","is","fit","on","an","arange",",","if","'level","'",",","it","is","fit","on","the","one","vector",".","lshort",":","bool",",","optional","(","default=True",")","Whether","or","not","to","truncate","the","``","l","``","value","in","the","C","code",".","Notes","--","--","-","This","test","is","generally","used","indirectly","via","the",":","func",":","`","pmdarima.arima.ndiffs","`","function",",","which","computes","the","differencing","term",",","``","d","``",".","References","--","--","--","--","--","..","[","1","]","R","'s","tseries","KPSS","test","source","code",":","http",":","\/\/bit.ly\/2eJP1IU"]
docstr: Test whether the time series is stationary or needs differencing.
  
  Parameters
  ----------
  x : array-like, shape=(n_samples,)
      The time series vector.
  
  Returns
  -------
  pval : float
      The computed P-value of the test.
  
  sig : bool
      Whether the P-value is significant at the ``alpha`` level.
      More directly, whether to difference the time series.
docstr_tok: ["Test","whether","the","time","series","is","stationary","or","needs","differencing",".","Parameters","--","--","--","--","--","x",":","array-like",",","shape=","(","n_samples",",",")","The","time","series","vector",".","Returns","--","--","--","-","pval",":","float","The","computed","P-value","of","the","test",".","sig",":","bool","Whether","the","P-value","is","significant","at","the","``","alpha","``","level",".","More","directly",",","whether","to","difference","the","time","series","."]
code: def should_diff(self, x):
      """Test whether the time series is stationary or needs differencing.
  
      Parameters
      ----------
      x : array-like, shape=(n_samples,)
          The time series vector.
  
      Returns
      -------
      pval : float
          The computed P-value of the test.
  
      sig : bool
          Whether the P-value is significant at the ``alpha`` level.
          More directly, whether to difference the time series.
      """
      if not self._base_case(x):
          return np.nan, False
  
      # ensure vector
      x = check_endog(x, dtype=DTYPE, preserve_series=False)
      n = x.shape[0]
  
      # check on status of null
      null = self.null
  
      # fit a model on an arange to determine the residuals
      if null == "trend":
          t = np.arange(n).reshape(n, 1)
  
          # these numbers came out of the R code.. I've found 0 doc for these
          table = c(0.216, 0.176, 0.146, 0.119)
      elif null == "level":
          t = np.ones(n).reshape(n, 1)
  
          # these numbers came out of the R code.. I've found 0 doc for these
          table = c(0.739, 0.574, 0.463, 0.347)
      else:
          raise ValueError("null must be one of %r" % self._valid)
  
      # fit the model
      lm = LinearRegression().fit(t, x)
      e = x - lm.predict(t)  # residuals
  
      s = np.cumsum(e)
      eta = (s * s).sum() / (n**2)
      s2 = (e * e).sum() / n
  
      # scalar, denom = 10, 14
      # if self.lshort:
      #     scalar, denom = 3, 13
      # l_ = int(np.trunc(scalar * np.sqrt(n) / denom))
      if self.lshort:
          l_ = int(np.trunc(4 * (n / 100) ** 0.25))
      else:
          l_ = int(np.trunc(12 * (n / 100) ** 0.25))
  
      # compute the C subroutine
      s2 = C_tseries_pp_sum(e, n, l_, s2)
      stat = eta / s2
  
      # do approximation
      _, pval = approx(table, self.tablep, xout=stat, rule=2)
  
      # R does a test for rule=1, but we don't want to do that, because they
      # just do it to issue a warning in case the P-value is smaller/greater
      # than the printed value is.
      return pval[0], pval[0] < self.alpha
  
imports: from sklearn.base import BaseEstimator
  from sklearn.linear_model import LinearRegression
  from statsmodels import api
  from abc import ABCMeta, abstractmethod
  import numpy
  from ..compat.numpy import DTYPE
  from ..decorators import deprecated
  from ..utils.array import c, diff, check_endog
  from .approx import approx
  from ._arima import C_tseries_pp_sum
label_desc: Use image node_id 2 for calling the KPSSTest obj's underlying member method code with example usage: obj.should_diff(x) and returns: pval,  unknown, np,  False