Given a time series, fit a non-seasonal ARIMA model of order (p, d, q), where p represents
    the autoregression terms, d represents the order of differencing, and q moving average error
    terms. If includeIntercept is true, the model is fitted with an intercept. In order to select
    the appropriate order of the model, users are advised to inspect ACF and PACF plots, or compare
    the values of the objective function. Finally, while the current implementation of
    `fitModel` verifies that parameters fit stationarity and invertibility requirements,
    there is currently no function to transform them if they do not. It is up to the user
    to make these changes as appropriate (or select a different model specification)

    Parameters
    ----------
    p:
        autoregressive order
    d:
        differencing order
    q:
        moving average order
    ts:
        time series to which to fit an ARIMA(p, d, q) model as a Numpy array.
    includeIntercept:
        if true the model is fit with an intercept term. Default is true
    method:
        objective function and optimization method, current options are 'css-bobyqa',
        and 'css-cgd'. Both optimize the log likelihood in terms of the
        conditional sum of squares. The first uses BOBYQA for optimization, while
        the second uses conjugate gradient descent. Default is 'css-cgd'
    userInitParams:
        A set of user provided initial parameters for optimization as a float list.
        If null (default), initialized using Hannan-Rissanen algorithm. If provided,
        order of parameter should be: intercept term, AR parameters (in
        increasing order of lag), MA parameters (in increasing order of lag).
    sc:
        The SparkContext, required.
    
    returns an ARIMAModel

def fit_model(p, d, q, ts, includeIntercept=True, method="css-cgd", userInitParams=None, sc=None):
    """
    Given a time series, fit a non-seasonal ARIMA model of order (p, d, q), where p represents
    the autoregression terms, d represents the order of differencing, and q moving average error
    terms. If includeIntercept is true, the model is fitted with an intercept. In order to select
    the appropriate order of the model, users are advised to inspect ACF and PACF plots, or compare
    the values of the objective function. Finally, while the current implementation of
    `fitModel` verifies that parameters fit stationarity and invertibility requirements,
    there is currently no function to transform them if they do not. It is up to the user
    to make these changes as appropriate (or select a different model specification)

    Parameters
    ----------
    p:
        autoregressive order
    d:
        differencing order
    q:
        moving average order
    ts:
        time series to which to fit an ARIMA(p, d, q) model as a Numpy array.
    includeIntercept:
        if true the model is fit with an intercept term. Default is true
    method:
        objective function and optimization method, current options are 'css-bobyqa',
        and 'css-cgd'. Both optimize the log likelihood in terms of the
        conditional sum of squares. The first uses BOBYQA for optimization, while
        the second uses conjugate gradient descent. Default is 'css-cgd'
    userInitParams:
        A set of user provided initial parameters for optimization as a float list.
        If null (default), initialized using Hannan-Rissanen algorithm. If provided,
        order of parameter should be: intercept term, AR parameters (in
        increasing order of lag), MA parameters (in increasing order of lag).
    sc:
        The SparkContext, required.
    
    returns an ARIMAModel
    """
    assert sc != None, "Missing SparkContext"
    
    jvm = sc._jvm
    jmodel = jvm.com.cloudera.sparkts.models.ARIMA.fitModel(p, d, q, _py2java(sc, Vectors.dense(ts)), includeIntercept, method, _py2java_double_array(sc, userInitParams))
    return ARIMAModel(jmodel=jmodel, sc=sc)