def fit(self, input_relation: Union[(vDataFrame, str)], y: str, ts: str, X: list=[], test_relation: Union[(vDataFrame, str)]=''):
    '\n    ---------------------------------------------------------------------------\n    Trains the model.\n\n    Parameters\n    ----------\n    input_relation: str/vDataFrame\n        Training relation.\n    y: str\n        Response column.\n    ts: str\n        vcolumn used to order the data.\n    X: list, optional\n        exogenous columns used to fit the model.\n    test_relation: str/vDataFrame, optional\n        Relation used to test the model.\n\n    Returns\n    -------\n    object\n        model\n        '
    check_types([('input_relation', input_relation, [str, vDataFrame]), ('y', y, [str]), ('test_relation', test_relation, [str, vDataFrame]), ('ts', ts, [str])])
    self.cursor = check_cursor(self.cursor, input_relation, True)[0]
    does_model_exist(name=self.name, cursor=self.cursor, raise_error=True)
    self.input_relation = (input_relation if isinstance(input_relation, str) else input_relation.__genSQL__())
    if isinstance(test_relation, vDataFrame):
        self.test_relation = test_relation.__genSQL__()
    elif test_relation:
        self.test_relation = test_relation
    else:
        self.test_relation = self.input_relation
    (self.y, self.ts, self.deploy_predict_) = (str_column(y), str_column(ts), '')
    self.coef_ = tablesample({'predictor': [], 'coefficient': []})
    (self.ma_avg_, self.ma_piq_) = (None, None)
    (X, schema) = ([str_column(elem) for elem in X], schema_relation(self.name)[0])
    (self.X, self.exogenous) = ([], X)
    relation = '(SELECT *, [VerticaPy_y] AS VerticaPy_y_copy FROM {}) VERTICAPY_SUBTABLE '
    model = LinearRegression(name=self.name, solver=self.parameters['solver'], max_iter=self.parameters['max_iter'], tol=self.parameters['tol'])
    if ((self.parameters['p'] == 0) and (self.parameters['q'] == 0) and (self.parameters['d'] == 0) and (self.parameters['s'] == 0) and (not self.exogenous)):
        query = 'SELECT AVG({}) FROM {}'.format(self.y, self.input_relation)
        self.ma_avg_ = self.cursor.execute(query).fetchone()[0]
        self.deploy_predict_ = str(self.ma_avg_)
    if (self.parameters['d'] > 0):
        for i in range(self.parameters['d']):
            relation = '(SELECT [VerticaPy_y] - LAG([VerticaPy_y], 1) OVER (ORDER BY [VerticaPy_ts]) AS [VerticaPy_y], VerticaPy_y_copy[VerticaPy_key_columns] FROM {}) VERTICAPY_SUBTABLE'.format(relation)
    if ((self.parameters['D'] > 0) and (self.parameters['s'] > 0)):
        for i in range(self.parameters['D']):
            relation = '(SELECT [VerticaPy_y] - LAG([VerticaPy_y], {}) OVER (ORDER BY [VerticaPy_ts]) AS [VerticaPy_y], VerticaPy_y_copy[VerticaPy_key_columns] FROM {}) VERTICAPY_SUBTABLE'.format(self.parameters['s'], relation)

    def drop_temp_elem(self, schema):
        try:
            with warnings.catch_warnings(record=True) as w:
                drop('{}.VERTICAPY_TEMP_MODEL_LINEAR_REGRESSION_VIEW_{}'.format(schema, get_session(self.cursor)), cursor=self.cursor, method='view')
        except:
            pass
    if ((self.parameters['p'] > 0) or (self.parameters['P'] > 0)):
        columns = ['LAG([VerticaPy_y], {}) OVER (ORDER BY [VerticaPy_ts]) AS AR{}'.format(i, i) for i in range(1, (self.parameters['p'] + 1))]
        AR = ['AR{}'.format(i) for i in range(1, (self.parameters['p'] + 1))]
        if (self.parameters['s'] > 0):
            for i in range(1, (self.parameters['P'] + 1)):
                if ((i * self.parameters['s']) not in range(1, (self.parameters['p'] + 1))):
                    columns += ['LAG([VerticaPy_y], {}) OVER (ORDER BY [VerticaPy_ts]) AS AR{}'.format((i * self.parameters['s']), (i * self.parameters['s']))]
                    AR += ['AR{}'.format((i * self.parameters['s']))]
        relation = '(SELECT *, {} FROM {}) VERTICAPY_SUBTABLE'.format(', '.join(columns), relation)
        drop_temp_elem(self, schema)
        query = 'CREATE VIEW {}.VERTICAPY_TEMP_MODEL_LINEAR_REGRESSION_VIEW_{} AS SELECT * FROM {}'.format(schema, get_session(self.cursor), relation.format(self.input_relation).replace('[VerticaPy_ts]', self.ts).replace('[VerticaPy_y]', self.y).replace('[VerticaPy_key_columns]', (', ' + ', '.join(([self.ts] + X)))))
        try:
            self.cursor.execute(query)
            self.X += (AR + X)
            model.fit(input_relation='{}.VERTICAPY_TEMP_MODEL_LINEAR_REGRESSION_VIEW_{}'.format(schema, get_session(self.cursor)), X=self.X, y=self.y)
        except:
            drop_temp_elem(self, schema)
            raise
        drop_temp_elem(self, schema)
        self.coef_.values['predictor'] = model.coef_.values['predictor']
        self.coef_.values['coefficient'] = model.coef_.values['coefficient']
        alphaq = model.coef_.values['coefficient']
        model.drop()
        epsilon_final = ((('[VerticaPy_y] - ' + str(alphaq[0])) + ' - ') + ' - '.join([((str(alphaq[i]) + ' * ') + 'LAG([VerticaPy_y], {}) OVER (ORDER BY [VerticaPy_ts])'.format(i)) for i in range(1, (self.parameters['p'] + 1))]))
        self.deploy_predict_ = ((str(alphaq[0]) + ' + ') + ' + '.join([((str(alphaq[i]) + ' * ') + 'LAG(VerticaPy_y_copy, {}) OVER (ORDER BY [VerticaPy_ts])'.format(i)) for i in range(1, (self.parameters['p'] + 1))]))
        if ((self.parameters['s'] > 0) and (self.parameters['P'] > 0)):
            epsilon_final += (' - ' + ' - '.join([((str(alphaq[i]) + ' * ') + 'LAG([VerticaPy_y], {}) OVER (ORDER BY [VerticaPy_ts])'.format((i * self.parameters['s']))) for i in range((self.parameters['p'] + 1), ((self.parameters['p'] + (self.parameters['P'] if (self.parameters['s'] > 0) else 0)) + 1))]))
            self.deploy_predict_ += (' + ' + ' + '.join([((str(alphaq[i]) + ' * ') + 'LAG(VerticaPy_y_copy, {}) OVER (ORDER BY [VerticaPy_ts])'.format((i * self.parameters['s']))) for i in range((self.parameters['p'] + 1), ((self.parameters['p'] + (self.parameters['P'] if (self.parameters['s'] > 0) else 0)) + 1))]))
        for (idx, elem) in enumerate(X):
            epsilon_final += ' - {} * [X{}]'.format(alphaq[(((idx + self.parameters['p']) + (self.parameters['P'] if (self.parameters['s'] > 0) else 0)) + 1)], idx)
            self.deploy_predict_ += ' + {} * [X{}]'.format(alphaq[(((idx + self.parameters['p']) + (self.parameters['P'] if (self.parameters['s'] > 0) else 0)) + 1)], idx)
        relation = '(SELECT {} AS [VerticaPy_y], {}, VerticaPy_y_copy[VerticaPy_key_columns] FROM {}) VERTICAPY_SUBTABLE'.format(epsilon_final, ', '.join(AR), relation)
    if ((self.parameters['q'] > 0) or ((self.parameters['Q'] > 0) and (self.parameters['s'] > 0))):
        transform_relation = relation.replace('[VerticaPy_y]', y).replace('[VerticaPy_ts]', ts)
        transform_relation = transform_relation.replace('[VerticaPy_key_columns]', (', ' + ', '.join((X + [ts]))))
        for (idx, elem) in enumerate(X):
            transform_relation = transform_relation.replace('[X{}]'.format(idx), elem)
        query = 'SELECT COUNT(*), AVG({}) FROM {}'.format(self.y, transform_relation.format(self.input_relation))
        result = self.cursor.execute(query).fetchone()
        self.ma_avg_ = result[1]
        n = result[0]
        n = max(max(min(max((n ** (1.0 / 3.0)), 8), self.parameters['papprox_ma']), self.parameters['q']), ((self.parameters['Q'] * self.parameters['s']) + 1))
        n = int(n)
        columns = ['LAG([VerticaPy_y], {}) OVER (ORDER BY [VerticaPy_ts]) AS ARq{}'.format(i, i) for i in range(1, n)]
        ARq = ['ARq{}'.format(i) for i in range(1, n)]
        tmp_relation = '(SELECT *, {} FROM {}) VERTICAPY_SUBTABLE'.format(', '.join(columns), relation)
        for (idx, elem) in enumerate(X):
            tmp_relation = tmp_relation.replace('[X{}]'.format(idx), elem)
        drop_temp_elem(self, schema)
        query = 'CREATE VIEW {}.VERTICAPY_TEMP_MODEL_LINEAR_REGRESSION_VIEW_{} AS SELECT * FROM {}'.format(schema, get_session(self.cursor), tmp_relation.format(self.input_relation).replace('[VerticaPy_ts]', self.ts).replace('[VerticaPy_y]', self.y).replace('[VerticaPy_key_columns]', (', ' + ', '.join(([self.ts] + X)))))
        try:
            self.cursor.execute(query)
            model.fit(input_relation='{}.VERTICAPY_TEMP_MODEL_LINEAR_REGRESSION_VIEW_{}'.format(schema, get_session(self.cursor)), X=ARq, y=self.y)
        except:
            drop_temp_elem(self, schema)
            raise
        drop_temp_elem(self, schema)
        if (not self.coef_.values['predictor']):
            self.coef_.values['predictor'] += ['Intercept']
            self.coef_.values['coefficient'] += [self.ma_avg_]
            self.deploy_predict_ = str(self.ma_avg_)
        alphaq = model.coef_.values['coefficient'][1:]
        model.drop()
        (thetaq, piq) = ([], ([(- 1)] + []))
        for j in range(0, len(alphaq)):
            thetaq += [(sum([(alphaq[((j - i) - 1)] * thetaq[i]) for i in range(0, j)]) + alphaq[j])]
        for j in range(self.parameters['q']):
            self.coef_.values['predictor'] += ['ma{}'.format((j + 1))]
            self.coef_.values['coefficient'] += [thetaq[j]]
            self.deploy_predict_ += ' + {} * MA{}'.format(thetaq[j], (j + 1))
        if (self.parameters['s'] > 0):
            for j in range(1, (self.parameters['Q'] + 1)):
                self.coef_.values['predictor'] += ['ma{}'.format((self.parameters['s'] * j))]
                self.coef_.values['coefficient'] += [thetaq[((self.parameters['s'] * j) - 1)]]
                self.deploy_predict_ += ' + {} * MA{}'.format(thetaq[((self.parameters['s'] * j) - 1)], (self.parameters['s'] * j))
        for j in range(0, self.parameters['max_pik']):
            piq_tmp = 0
            for i in range(0, self.parameters['q']):
                if ((j - i) > 0):
                    piq_tmp -= (thetaq[i] * piq[(j - i)])
                elif ((j - i) == 0):
                    piq_tmp -= thetaq[i]
            piq = (piq + [piq_tmp])
        self.ma_piq_ = tablesample({'coefficient': piq})
        epsilon = ((('[VerticaPy_y] - ' + str(self.ma_avg_)) + ' - ') + ' - '.join([((str(piq[i]) + ' * ') + 'LAG([VerticaPy_y] - {}, {}) OVER (ORDER BY [VerticaPy_ts])'.format(self.ma_avg_, i)) for i in range(1, self.parameters['max_pik'])]))
        epsilon += ' AS MA0'
        relation = '(SELECT *, {} FROM {}) VERTICAPY_SUBTABLE'.format(epsilon, relation)
        columns = ['LAG(MA0, {}) OVER (ORDER BY [VerticaPy_ts]) AS MA{}'.format(i, i) for i in range(1, (self.parameters['q'] + 1))]
        MA = ['MA{}'.format(i) for i in range(1, (self.parameters['q'] + 1))]
        if (self.parameters['s'] > 0):
            columns += ['LAG(MA0, {}) OVER (ORDER BY [VerticaPy_ts]) AS MA{}'.format((i * self.parameters['s']), (i * self.parameters['s'])) for i in range(1, (self.parameters['Q'] + 1))]
            MA += ['MA{}'.format((i * self.parameters['s'])) for i in range(1, (self.parameters['Q'] + 1))]
        relation = '(SELECT *, {} FROM {}) VERTICAPY_SUBTABLE'.format(', '.join(columns), relation)
        self.X += MA
        transform_relation = relation.replace('[VerticaPy_y]', y).replace('[VerticaPy_ts]', ts)
        transform_relation = transform_relation.replace('[VerticaPy_key_columns]', (', ' + ', '.join((X + [ts]))))
        for (idx, elem) in enumerate(X):
            transform_relation = transform_relation.replace('[X{}]'.format(idx), elem)
    self.transform_relation = relation
    model_save = {'type': 'SARIMAX', 'input_relation': self.input_relation, 'test_relation': self.test_relation, 'transform_relation': self.transform_relation, 'deploy_predict': self.deploy_predict_, 'ma_avg': self.ma_avg_, 'ma_piq': (self.ma_piq_.values if self.ma_piq_ else None), 'X': self.X, 'y': self.y, 'ts': self.ts, 'exogenous': self.exogenous, 'coef': self.coef_.values, 'p': self.parameters['p'], 'd': self.parameters['d'], 'q': self.parameters['q'], 'P': self.parameters['P'], 'D': self.parameters['D'], 'Q': self.parameters['Q'], 's': self.parameters['s'], 'tol': self.parameters['tol'], 'max_iter': self.parameters['max_iter'], 'solver': self.parameters['solver'], 'max_pik': self.parameters['max_pik'], 'papprox_ma': self.parameters['papprox_ma']}
    insert_verticapy_schema(model_name=self.name, model_type='SARIMAX', model_save=model_save, cursor=self.cursor)
    return self
---------------------------------------------------------------------------
Trains the model.

Parameters
----------
input_relation: str/vDataFrame
    Training relation.
y: str
    Response column.
ts: str
    vcolumn used to order the data.
X: list, optional
    exogenous columns used to fit the model.
test_relation: str/vDataFrame, optional
    Relation used to test the model.

Returns
-------
object
    model
def fit(self, input_relation: Union[(vDataFrame, str)], y: str, ts: str, X: list=[], test_relation: Union[(vDataFrame, str)]=):
    '\n    ---------------------------------------------------------------------------\n    Trains the model.\n\n    Parameters\n    ----------\n    input_relation: str/vDataFrame\n        Training relation.\n    y: str\n        Response column.\n    ts: str\n        vcolumn used to order the data.\n    X: list, optional\n        exogenous columns used to fit the model.\n    test_relation: str/vDataFrame, optional\n        Relation used to test the model.\n\n    Returns\n    -------\n    object\n        model\n        '
    check_types([('input_relation', input_relation, [str, vDataFrame]), ('y', y, [str]), ('test_relation', test_relation, [str, vDataFrame]), ('ts', ts, [str])])
    self.cursor = check_cursor(self.cursor, input_relation, True)[0]
    does_model_exist(name=self.name, cursor=self.cursor, raise_error=True)
    self.input_relation = (input_relation if isinstance(input_relation, str) else input_relation.__genSQL__())
    if isinstance(test_relation, vDataFrame):
        self.test_relation = test_relation.__genSQL__()
    elif test_relation:
        self.test_relation = test_relation
    else:
        self.test_relation = self.input_relation
    (self.y, self.ts, self.deploy_predict_) = (str_column(y), str_column(ts), )
    self.coef_ = tablesample({'predictor': [], 'coefficient': []})
    (self.ma_avg_, self.ma_piq_) = (None, None)
    (X, schema) = ([str_column(elem) for elem in X], schema_relation(self.name)[0])
    (self.X, self.exogenous) = ([], X)
    relation = '(SELECT *, [VerticaPy_y] AS VerticaPy_y_copy FROM {}) VERTICAPY_SUBTABLE '
    model = LinearRegression(name=self.name, solver=self.parameters['solver'], max_iter=self.parameters['max_iter'], tol=self.parameters['tol'])
    if ((self.parameters['p'] == 0) and (self.parameters['q'] == 0) and (self.parameters['d'] == 0) and (self.parameters['s'] == 0) and (not self.exogenous)):
        query = 'SELECT AVG({}) FROM {}'.format(self.y, self.input_relation)
        self.ma_avg_ = self.cursor.execute(query).fetchone()[0]
        self.deploy_predict_ = str(self.ma_avg_)
    if (self.parameters['d'] > 0):
        for i in range(self.parameters['d']):
            relation = '(SELECT [VerticaPy_y] - LAG([VerticaPy_y], 1) OVER (ORDER BY [VerticaPy_ts]) AS [VerticaPy_y], VerticaPy_y_copy[VerticaPy_key_columns] FROM {}) VERTICAPY_SUBTABLE'.format(relation)
    if ((self.parameters['D'] > 0) and (self.parameters['s'] > 0)):
        for i in range(self.parameters['D']):
            relation = '(SELECT [VerticaPy_y] - LAG([VerticaPy_y], {}) OVER (ORDER BY [VerticaPy_ts]) AS [VerticaPy_y], VerticaPy_y_copy[VerticaPy_key_columns] FROM {}) VERTICAPY_SUBTABLE'.format(self.parameters['s'], relation)

    def drop_temp_elem(self, schema):
        try:
            with warnings.catch_warnings(record=True) as w:
                drop('{}.VERTICAPY_TEMP_MODEL_LINEAR_REGRESSION_VIEW_{}'.format(schema, get_session(self.cursor)), cursor=self.cursor, method='view')
        except:
            pass
    if ((self.parameters['p'] > 0) or (self.parameters['P'] > 0)):
        columns = ['LAG([VerticaPy_y], {}) OVER (ORDER BY [VerticaPy_ts]) AS AR{}'.format(i, i) for i in range(1, (self.parameters['p'] + 1))]
        AR = ['AR{}'.format(i) for i in range(1, (self.parameters['p'] + 1))]
        if (self.parameters['s'] > 0):
            for i in range(1, (self.parameters['P'] + 1)):
                if ((i * self.parameters['s']) not in range(1, (self.parameters['p'] + 1))):
                    columns += ['LAG([VerticaPy_y], {}) OVER (ORDER BY [VerticaPy_ts]) AS AR{}'.format((i * self.parameters['s']), (i * self.parameters['s']))]
                    AR += ['AR{}'.format((i * self.parameters['s']))]
        relation = '(SELECT *, {} FROM {}) VERTICAPY_SUBTABLE'.format(', '.join(columns), relation)
        drop_temp_elem(self, schema)
        query = 'CREATE VIEW {}.VERTICAPY_TEMP_MODEL_LINEAR_REGRESSION_VIEW_{} AS SELECT * FROM {}'.format(schema, get_session(self.cursor), relation.format(self.input_relation).replace('[VerticaPy_ts]', self.ts).replace('[VerticaPy_y]', self.y).replace('[VerticaPy_key_columns]', (', ' + ', '.join(([self.ts] + X)))))
        try:
            self.cursor.execute(query)
            self.X += (AR + X)
            model.fit(input_relation='{}.VERTICAPY_TEMP_MODEL_LINEAR_REGRESSION_VIEW_{}'.format(schema, get_session(self.cursor)), X=self.X, y=self.y)
        except:
            drop_temp_elem(self, schema)
            raise
        drop_temp_elem(self, schema)
        self.coef_.values['predictor'] = model.coef_.values['predictor']
        self.coef_.values['coefficient'] = model.coef_.values['coefficient']
        alphaq = model.coef_.values['coefficient']
        model.drop()
        epsilon_final = ((('[VerticaPy_y] - ' + str(alphaq[0])) + ' - ') + ' - '.join([((str(alphaq[i]) + ' * ') + 'LAG([VerticaPy_y], {}) OVER (ORDER BY [VerticaPy_ts])'.format(i)) for i in range(1, (self.parameters['p'] + 1))]))
        self.deploy_predict_ = ((str(alphaq[0]) + ' + ') + ' + '.join([((str(alphaq[i]) + ' * ') + 'LAG(VerticaPy_y_copy, {}) OVER (ORDER BY [VerticaPy_ts])'.format(i)) for i in range(1, (self.parameters['p'] + 1))]))
        if ((self.parameters['s'] > 0) and (self.parameters['P'] > 0)):
            epsilon_final += (' - ' + ' - '.join([((str(alphaq[i]) + ' * ') + 'LAG([VerticaPy_y], {}) OVER (ORDER BY [VerticaPy_ts])'.format((i * self.parameters['s']))) for i in range((self.parameters['p'] + 1), ((self.parameters['p'] + (self.parameters['P'] if (self.parameters['s'] > 0) else 0)) + 1))]))
            self.deploy_predict_ += (' + ' + ' + '.join([((str(alphaq[i]) + ' * ') + 'LAG(VerticaPy_y_copy, {}) OVER (ORDER BY [VerticaPy_ts])'.format((i * self.parameters['s']))) for i in range((self.parameters['p'] + 1), ((self.parameters['p'] + (self.parameters['P'] if (self.parameters['s'] > 0) else 0)) + 1))]))
        for (idx, elem) in enumerate(X):
            epsilon_final += ' - {} * [X{}]'.format(alphaq[(((idx + self.parameters['p']) + (self.parameters['P'] if (self.parameters['s'] > 0) else 0)) + 1)], idx)
            self.deploy_predict_ += ' + {} * [X{}]'.format(alphaq[(((idx + self.parameters['p']) + (self.parameters['P'] if (self.parameters['s'] > 0) else 0)) + 1)], idx)
        relation = '(SELECT {} AS [VerticaPy_y], {}, VerticaPy_y_copy[VerticaPy_key_columns] FROM {}) VERTICAPY_SUBTABLE'.format(epsilon_final, ', '.join(AR), relation)
    if ((self.parameters['q'] > 0) or ((self.parameters['Q'] > 0) and (self.parameters['s'] > 0))):
        transform_relation = relation.replace('[VerticaPy_y]', y).replace('[VerticaPy_ts]', ts)
        transform_relation = transform_relation.replace('[VerticaPy_key_columns]', (', ' + ', '.join((X + [ts]))))
        for (idx, elem) in enumerate(X):
            transform_relation = transform_relation.replace('[X{}]'.format(idx), elem)
        query = 'SELECT COUNT(*), AVG({}) FROM {}'.format(self.y, transform_relation.format(self.input_relation))
        result = self.cursor.execute(query).fetchone()
        self.ma_avg_ = result[1]
        n = result[0]
        n = max(max(min(max((n ** (1.0 / 3.0)), 8), self.parameters['papprox_ma']), self.parameters['q']), ((self.parameters['Q'] * self.parameters['s']) + 1))
        n = int(n)
        columns = ['LAG([VerticaPy_y], {}) OVER (ORDER BY [VerticaPy_ts]) AS ARq{}'.format(i, i) for i in range(1, n)]
        ARq = ['ARq{}'.format(i) for i in range(1, n)]
        tmp_relation = '(SELECT *, {} FROM {}) VERTICAPY_SUBTABLE'.format(', '.join(columns), relation)
        for (idx, elem) in enumerate(X):
            tmp_relation = tmp_relation.replace('[X{}]'.format(idx), elem)
        drop_temp_elem(self, schema)
        query = 'CREATE VIEW {}.VERTICAPY_TEMP_MODEL_LINEAR_REGRESSION_VIEW_{} AS SELECT * FROM {}'.format(schema, get_session(self.cursor), tmp_relation.format(self.input_relation).replace('[VerticaPy_ts]', self.ts).replace('[VerticaPy_y]', self.y).replace('[VerticaPy_key_columns]', (', ' + ', '.join(([self.ts] + X)))))
        try:
            self.cursor.execute(query)
            model.fit(input_relation='{}.VERTICAPY_TEMP_MODEL_LINEAR_REGRESSION_VIEW_{}'.format(schema, get_session(self.cursor)), X=ARq, y=self.y)
        except:
            drop_temp_elem(self, schema)
            raise
        drop_temp_elem(self, schema)
        if (not self.coef_.values['predictor']):
            self.coef_.values['predictor'] += ['Intercept']
            self.coef_.values['coefficient'] += [self.ma_avg_]
            self.deploy_predict_ = str(self.ma_avg_)
        alphaq = model.coef_.values['coefficient'][1:]
        model.drop()
        (thetaq, piq) = ([], ([(- 1)] + []))
        for j in range(0, len(alphaq)):
            thetaq += [(sum([(alphaq[((j - i) - 1)] * thetaq[i]) for i in range(0, j)]) + alphaq[j])]
        for j in range(self.parameters['q']):
            self.coef_.values['predictor'] += ['ma{}'.format((j + 1))]
            self.coef_.values['coefficient'] += [thetaq[j]]
            self.deploy_predict_ += ' + {} * MA{}'.format(thetaq[j], (j + 1))
        if (self.parameters['s'] > 0):
            for j in range(1, (self.parameters['Q'] + 1)):
                self.coef_.values['predictor'] += ['ma{}'.format((self.parameters['s'] * j))]
                self.coef_.values['coefficient'] += [thetaq[((self.parameters['s'] * j) - 1)]]
                self.deploy_predict_ += ' + {} * MA{}'.format(thetaq[((self.parameters['s'] * j) - 1)], (self.parameters['s'] * j))
        for j in range(0, self.parameters['max_pik']):
            piq_tmp = 0
            for i in range(0, self.parameters['q']):
                if ((j - i) > 0):
                    piq_tmp -= (thetaq[i] * piq[(j - i)])
                elif ((j - i) == 0):
                    piq_tmp -= thetaq[i]
            piq = (piq + [piq_tmp])
        self.ma_piq_ = tablesample({'coefficient': piq})
        epsilon = ((('[VerticaPy_y] - ' + str(self.ma_avg_)) + ' - ') + ' - '.join([((str(piq[i]) + ' * ') + 'LAG([VerticaPy_y] - {}, {}) OVER (ORDER BY [VerticaPy_ts])'.format(self.ma_avg_, i)) for i in range(1, self.parameters['max_pik'])]))
        epsilon += ' AS MA0'
        relation = '(SELECT *, {} FROM {}) VERTICAPY_SUBTABLE'.format(epsilon, relation)
        columns = ['LAG(MA0, {}) OVER (ORDER BY [VerticaPy_ts]) AS MA{}'.format(i, i) for i in range(1, (self.parameters['q'] + 1))]
        MA = ['MA{}'.format(i) for i in range(1, (self.parameters['q'] + 1))]
        if (self.parameters['s'] > 0):
            columns += ['LAG(MA0, {}) OVER (ORDER BY [VerticaPy_ts]) AS MA{}'.format((i * self.parameters['s']), (i * self.parameters['s'])) for i in range(1, (self.parameters['Q'] + 1))]
            MA += ['MA{}'.format((i * self.parameters['s'])) for i in range(1, (self.parameters['Q'] + 1))]
        relation = '(SELECT *, {} FROM {}) VERTICAPY_SUBTABLE'.format(', '.join(columns), relation)
        self.X += MA
        transform_relation = relation.replace('[VerticaPy_y]', y).replace('[VerticaPy_ts]', ts)
        transform_relation = transform_relation.replace('[VerticaPy_key_columns]', (', ' + ', '.join((X + [ts]))))
        for (idx, elem) in enumerate(X):
            transform_relation = transform_relation.replace('[X{}]'.format(idx), elem)
    self.transform_relation = relation
    model_save = {'type': 'SARIMAX', 'input_relation': self.input_relation, 'test_relation': self.test_relation, 'transform_relation': self.transform_relation, 'deploy_predict': self.deploy_predict_, 'ma_avg': self.ma_avg_, 'ma_piq': (self.ma_piq_.values if self.ma_piq_ else None), 'X': self.X, 'y': self.y, 'ts': self.ts, 'exogenous': self.exogenous, 'coef': self.coef_.values, 'p': self.parameters['p'], 'd': self.parameters['d'], 'q': self.parameters['q'], 'P': self.parameters['P'], 'D': self.parameters['D'], 'Q': self.parameters['Q'], 's': self.parameters['s'], 'tol': self.parameters['tol'], 'max_iter': self.parameters['max_iter'], 'solver': self.parameters['solver'], 'max_pik': self.parameters['max_pik'], 'papprox_ma': self.parameters['papprox_ma']}
    insert_verticapy_schema(model_name=self.name, model_type='SARIMAX', model_save=model_save, cursor=self.cursor)
    return self