Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Automatic stationary conversion

def make_stationary(data: pd.Series, alpha: float = 0.05, max_diff_order: int = 10) -> dict:
    # Test to see if the time series is already stationary
    if adfuller(data)[1] < alpha:
        return {
            'differencing_order': 0,
            'time_series': np.array(data)
        }
    
    # A list to store P-Values
    p_values = []
    
    # Test for differencing orders from 1 to max_diff_order (included)
    for i in range(1, max_diff_order + 1):
        # Perform ADF test
        result = adfuller(data.diff(i).dropna())
        # Append P-value
        p_values.append((i, result[1]))
        
    # Keep only those where P-value is lower than significance level
    significant = [p for p in p_values if p[1] < alpha]
    # Sort by the differencing order
    significant = sorted(significant, key=lambda x: x[0])
    
    # Get the differencing order
    diff_order = significant[0][0]
    
    # Make the time series stationary
    stationary_series = data.diff(diff_order).dropna()
    
    return {
        'differencing_order': diff_order,
        'time_series': np.array(stationary_series)
    }
Comment

PREVIOUS NEXT
Code Example
Python :: subplots whitespace 
Python :: how to see what variable is closest to a higher element in python 
Python :: to the power python markdown 
Python :: repeat every entru n times 
Python :: django router multiple pk 
Python :: prime number program in python using function 
Python :: boolean meaning in python 
Python :: how to make a relationship in python 
Python :: Python - Cómo comprobar si dos cuerdas son anagramas 
Python :: df filter by multiple rules python 
Python :: pandas ta quick start example 
Python :: handdle close window action in pyqt5 
Python :: display all rows pandas 
Python :: bill wiliams fractal python pandas 
Python :: [Solved]AttributeError: ‘numpy.ndarray’ object has no attribute ‘index’ 
Python :: python to open .seg file 
Python :: implementing a bubble sort in python 
Python :: Get timestamp with pyrhon 
Python :: wait until exe terminates python 
Python :: get multiples of a number between two numbers python 
Python :: pandas drop unnamed columns grebber 
Python :: struct is not defined python 
Python :: python set literal 
Python :: how to access rows and columns indexing numpy 
Python :: how to search on wikipedia with python and speak the result 
Python :: onetomany field 
Python :: Slice Age in Python 
Python :: Define a python function day_of_week, which displays the day name for a given date supplied in the form (day,month,year). 
Python :: Find & set values in pandas Dataframe 
Python :: como usar o Self no python 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =