trend_test
- hana_ml.algorithms.pal.tsa.trend_test.trend_test(data, key=None, endog=None, method=None, alpha=None)
Trend test is able to identify whether a time series has an upward or downward trend or not, and calculate the de-trended time series.
- Parameters
- dataDataFrame
Input data. At least two columns, one is ID column, the other is raw data.
- keystr, optional
The ID column.
Defaults to the first column of data if the index column of data is not provided. Otherwise, defaults to the index column of data.
- endogstr, optional
The column of series to be tested.
Defaults to the first non-ID column.
- method{'mk', 'difference-sign'}, optional
The method used to identify trend:
-'mk': Mann-Kendall test. -'difference-sign': Difference-sign test.
Defaults to 'mk'.
- alphafloat, optional
Significance value.
The value range is (0, 0.5).
Defaults to 0.05.
- Returns
- DataFrames
DataFrame 1 : statistics, structured as follows:
STAT_NAME: includes
TREND: -1 for downward trend, 0 for no trend, and 1 for upward trend
S: the number of positive pairs minus the negative pairs
P-VALUE: The p-value of the observed S
STAT_VALUE: value of stats above.
DataFrame 2 : detrended table, structured as follows:
ID : Time stamp that is monotonically increasing sorted.
DETRENDED_SERIES: The corresponding de-trended time series. The first value absents if trend presents.
Examples
Time series data df:
>>> df.collect().head() TIME_STAMP SERIES 0 1 1500 1 2 1510 2 3 1550
Perform trend_test function:
>>> stats, detrended = trend_test(data=df, key='TIME_STAMP', endog='SERIES', method='mk', alpha=0.05)
Outputs:
>>> stats.collect() STAT_NAME STAT_VALUE 0 TREND 1 1 S 60 2 P-VALUE 0.0000267...
>>> detrended.collect().head(2) ID DETRENDED_SERIES 0 2 10 1 3 40