ARIMA seasonal prediction with Python: x12a and x13as not found on path
Asked Answered
T

2

6

I am using Statsmodels to implement seasonal ARIMA prediction for time series. Here is my code :

import statsmodels.api  as sm
from statsmodels.tsa.x13 import x13_arima_select_order, _find_x12
import pandas
import scipy
import numpy
import imp
data_source = imp.load_source('data_source', '/mypath/')
def main():
    data=data_source.getdata()
    res = x13_arima_select_order(data)
    print (res.order, res.sorder)

main()

When running the code, I am getting this exception:

X13NotFoundError("x12a and x13as not found on path. Give the " statsmodels.tools.sm_exceptions.X13NotFoundError: x12a and x13as not found on path. Give the path, put them on PATH, or set the X12PATH or X13PATH environmental variable.

Transom answered 17/8, 2015 at 15:5 Comment(0)
S
8

From looking at the source code for statsmodels.tsa.x13 you need to have either the x12a or x13as binary applications installed on your system. In addition to that, the path to the folders where those binaries are located must be set in your user's PATH environment variable. You don't mention what operating system you're running, so here's a page with links to OS specific download pages on the left hand side to help you install the needed software. https://www.census.gov/srd/www/x13as/

This is the link to the source I'm referencing to figure out what you're missing in your environment: http://statsmodels.sourceforge.net/devel/_modules/statsmodels/tsa/x13.html

def x13_arima_analysis(endog, maxorder=(2, 1), maxdiff=(2, 1), diff=None,
                       exog=None, log=None, outlier=True, trading=False,
                       forecast_years=None, retspec=False,
                       speconly=False, start=None, freq=None,
                       print_stdout=False, x12path=None, prefer_x13=True):
...
    x12path = _check_x12(x12path)

    if not isinstance(endog, (pd.DataFrame, pd.Series)):
        if start is None or freq is None:
            raise ValueError("start and freq cannot be none if endog is not "
                             "a pandas object")
        endog = pd.Series(endog, index=pd.DatetimeIndex(start=start,
                                                        periods=len(endog),
                                                        freq=freq))

...

def _check_x12(x12path=None):
    x12path = _find_x12(x12path)
    if not x12path:
        raise X13NotFoundError("x12a and x13as not found on path. Give the "
                               "path, put them on PATH, or set the "
                               "X12PATH or X13PATH environmental variable.")
    return x12path

...

def _find_x12(x12path=None, prefer_x13=True):
    """
    If x12path is not given, then either x13as[.exe] or x12a[.exe] must
    be found on the PATH. Otherwise, the environmental variable X12PATH or
    X13PATH must be defined. If prefer_x13 is True, only X13PATH is searched
    for. If it is false, only X12PATH is searched for.
    """ 
Seaweed answered 17/8, 2015 at 15:39 Comment(1)
Glad to hear it. Cheers!Seaweed
H
0

To add to the accepted answer, in Linux you can set the X13PATH variable by opening

~/.bash_profile

and adding this new line:

export X13PATH="/your/path/to/x13"

Using this method permanently sets the path so you don't need to set it each time. You may need to log out and then log back in or disconnect and reconnect if using SSH after making the changes to the file for them to be applied.

If the error persists you can look in the x13.py source file from statsmodels. I found that the file was not up to date with the most recent names for the x13 executable files. The default code used

_binary_names = ('x13as.exe', 'x13as', 'x12a.exe', 'x12a')

While the newer version used:

_binary_names = ('x13as.exe', 'x13as', 'x12a.exe', 'x12a',
                 'x13as_ascii', 'x13as_html')

Updating _binary_names fixed the error.

Hoisch answered 21/10, 2022 at 18:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.