def test_innovations_algo_filter_kalman_filter(ar_params, ma_params, sigma2):
    # Test the innovations algorithm and filter against the Kalman filter
    # for exact likelihood evaluation of an ARMA process
    endog = np.random.normal(size=100)

    # Innovations algorithm approach
    llf = arma_innovations.arma_loglike(endog, ar_params, ma_params, sigma2)
    llf_obs = arma_innovations.arma_loglikeobs(endog, ar_params, ma_params,
                                               sigma2)
    score = arma_innovations.arma_score(endog, ar_params, ma_params, sigma2)
    score_obs = arma_innovations.arma_scoreobs(endog, ar_params, ma_params,
                                               sigma2)

    # Kalman filter apparoach
    mod = SARIMAX(endog, order=(len(ar_params), 0, len(ma_params)))
    params = np.r_[ar_params, ma_params, sigma2]

    # Test that the two approaches are the same
    assert_allclose(llf, mod.loglike(params))
    assert_allclose(llf_obs, mod.loglikeobs(params))
    # Note: the tolerance on the two gets worse as more nobs are added
    assert_allclose(score, mod.score(params), atol=1e-5)
    assert_allclose(score_obs, mod.score_obs(params), atol=1e-5)
Exemple #2
0
            max_evals=50,
            trials=Trials())

modelo = GBR(
    n_estimators=int(best['n_estimators']),
    learning_rate=best['learning_rate'],
    subsample=best['x_subsample'],
    alpha=best['x_alpha'],
    validation_fraction=best['x_validation_fraction'],
)

modelo.fit(X_train, y_train)  #MSE
y_pred = modelo.predict(X_test)
print('Mean squared error', mse(y_test, y_pred))

train_score = modelo.score(X_train, y_train)  #R2
test_score = modelo.score(X_test, y_test)
print('train R2:', train_score, '-- test R2:', test_score)

pred = df_merged.drop('Stocks_price_usd',
                      axis=1)  #Using trained model to predict data
res = modelo.predict(pred)

dffinal.drop(['Refiners_Cost_usd', 'usd', 'Stocks_price_usd', 'Pandemics'],
             axis=1,
             inplace=True)  # 3 column df to show results
dffinal.rename(columns={'Crude_oil_price_usd': 'Real'}, inplace=True)
dffinal['Predicitions'] = res
dffinal['Difference'] = dffinal.Predicitions - dffinal.Real

preds.insert(1, "Refiners_Cost_usd", [32.72, 25.80, 29.1],