How to use the pmdarima.auto_arima function in pmdarima

To help you get started, we’ve selected a few pmdarima examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alkaline-ml / pmdarima / examples / arima / example_auto_arima.py View on Github external
# Author: Taylor Smith 

import pmdarima as pm
from pmdarima import model_selection
from sklearn.metrics import mean_squared_error
import matplotlib.pyplot as plt
import numpy as np

# #############################################################################
# Load the data and split it into separate pieces
data = pm.datasets.load_lynx()
train, test = model_selection.train_test_split(data, train_size=90)

# Fit a simple auto_arima model
modl = pm.auto_arima(train, start_p=1, start_q=1, start_P=1, start_Q=1,
                     max_p=5, max_q=5, max_P=5, max_Q=5, seasonal=True,
                     stepwise=True, suppress_warnings=True, D=10, max_D=10,
                     error_action='ignore')

# Create predictions for the future, evaluate on test
preds, conf_int = modl.predict(n_periods=test.shape[0], return_conf_int=True)

# Print the error:
print("Test RMSE: %.3f" % np.sqrt(mean_squared_error(test, preds)))

# #############################################################################
# Plot the points and the forecasts
x_axis = np.arange(train.shape[0] + preds.shape[0])
x_years = x_axis + 1821  # Year starts at 1821

plt.plot(x_years[x_axis[:train.shape[0]]], train, alpha=0.75)
github alkaline-ml / pmdarima / examples / example_simple_fit.py View on Github external
print(__doc__)

# Author: Taylor Smith 

import pmdarima as pm
from pmdarima import model_selection
import numpy as np
from matplotlib import pyplot as plt

# #############################################################################
# Load the data and split it into separate pieces
data = pm.datasets.load_wineind()
train, test = model_selection.train_test_split(data, train_size=150)

# Fit a simple auto_arima model
arima = pm.auto_arima(train, error_action='ignore', trace=True,
                      suppress_warnings=True, maxiter=10,
                      seasonal=True, m=12)

# #############################################################################
# Plot actual test vs. forecasts:
x = np.arange(test.shape[0])
plt.scatter(x, test, marker='x')
plt.plot(x, arima.predict(n_periods=test.shape[0]))
plt.title('Actual test samples vs. forecasts')
plt.show()
github BBVA / timecop / engines / auto_arima.py View on Github external
if (len(lista_datos) > 100):
        lista_datos_orig=lista_datos
        lista_datos=lista_datos[len(lista_datos)-100:]
    else:
        lista_datos_orig=lista_datos

    if orig_size < 100:
        start_point =0
    else:
        start_point= int(orig_size) - 100
    lista_puntos = np.arange(start_point, orig_size,1)

    df, df_train, df_test = create_train_test(lista_puntos, lista_datos)

    engine_output={}
    stepwise_model =  pm.auto_arima(df_train['valores'], start_p=1, start_q=1, max_p=3, max_q=3, m=12,
                              start_P=0, seasonal=True, d=1, D=1, trace=False, approx=False,
                              error_action='ignore',  # don't want to know if an order does not work
                              suppress_warnings=True,  # don't want convergence warnings
                              c=False,
                              disp=-1,
                              stepwise=True)  # set to stepwise

    print ("Fitted first model")
    stepwise_model.fit(df_train['valores'])

    fit_forecast_pred = stepwise_model.predict_in_sample(df_train['valores'])
    fit_forecast = pd.DataFrame(fit_forecast_pred,index = df_train.index,columns=['Prediction'])

    future_forecast_pred = stepwise_model.predict(n_periods=len(df_test['valores']))
    future_forecast = pd.DataFrame(future_forecast_pred,index = df_test.index,columns=['Prediction'])
    print(df_test.index)
github alkaline-ml / pmdarima / develop / _downloads / example_add_new_samples.py View on Github external
print(__doc__)

# Author: Taylor Smith 

import pmdarima as pm
import matplotlib.pyplot as plt
import numpy as np

# #############################################################################
# Load the data and split it into separate pieces
data = pm.datasets.load_lynx()
train, test = data[:100], data[100:]

# #############################################################################
# Fit with some validation (cv) samples
arima = pm.auto_arima(train, start_p=1, start_q=1, d=0, max_p=5, max_q=5,
                      out_of_sample_size=10, suppress_warnings=True,
                      stepwise=True, error_action='ignore')

# Now plot the results and the forecast for the test set
preds, conf_int = arima.predict(n_periods=test.shape[0],
                                return_conf_int=True)

fig, axes = plt.subplots(2, 1, figsize=(12, 8))
x_axis = np.arange(train.shape[0] + preds.shape[0])
axes[0].plot(x_axis[:train.shape[0]], train, alpha=0.75)
axes[0].scatter(x_axis[train.shape[0]:], preds, alpha=0.4, marker='o')
axes[0].scatter(x_axis[train.shape[0]:], test, alpha=0.4, marker='x')
axes[0].fill_between(x_axis[-preds.shape[0]:], conf_int[:, 0], conf_int[:, 1],
                     alpha=0.1, color='b')

# fill the section where we "held out" samples in our model fit
github DUanalytics / pyAnalytics / 88-TS / 88P_pmdarima_lynx.py View on Github external
#%%%%%
import pmdarima as pm
import matplotlib.pyplot as plt
import numpy as np

###########################################
# Load the data and split it into separate pieces
data = pm.datasets.load_lynx()
data.shape  #0-99,100 to 114
train, test = data[:100], data[100:]

####################################################################
# Fit with some validation (cv) samples
arima = pm.auto_arima(train, start_p=1, start_q=1, d=0, max_p=5, max_q=5,  out_of_sample_size=10, suppress_warnings=True,   stepwise=True, error_action='ignore')

# Now plot the results and the forecast for the test set
preds, conf_int = arima.predict(n_periods=test.shape[0], return_conf_int =True)
preds
fig, axes = plt.subplots(2, 1, figsize=(12, 8))
x_axis = np.arange(train.shape[0] + preds.shape[0])
axes[0].plot(x_axis[:train.shape[0]], train, alpha=0.75)
axes[0].scatter(x_axis[train.shape[0]:], preds, alpha=0.4, marker='o')
axes[0].scatter(x_axis[train.shape[0]:], test, alpha=0.4, marker='x')
axes[0].fill_between(x_axis[-preds.shape[0]:], conf_int[:, 0], conf_int[:, 1],alpha=0.1, color='b')

# fill the section where we "held out" samples in our model fit
axes[0].set_title("Train samples & forecasted test samples")
# Now add the actual samples to the model and create NEW forecasts
arima.update(test)
new_preds, new_conf_int = arima.predict(n_periods=10, return_conf_int=True)
github DUanalytics / pyAnalytics / 88-TS / 88P_pmdarima_lynx.py View on Github external
#https://www.alkaline-ml.com/pmdarima/user_guide.html
import pmdarima as pm
#pip install pmdarima
from sklearn.metrics import mean_squared_error
import matplotlib.pyplot as plt
import numpy as np
#https://www.alkaline-ml.com/pmdarima/auto_examples/arima/example_auto_arima.html#sphx-glr-auto-examples-arima-example-auto-arima-py
##########################################################
# Load the data and split it into separate pieces
data = pm.datasets.load_lynx()
data
data.shape
train, test = data[:90], data[90:]
train.shape, test.shape
# Fit a simple auto_arima model
tsmodel = pm.auto_arima(train, start_p=1, start_q=1, start_P=1, start_Q=1, max_p=5, max_q=5, max_P=5, max_Q=5, seasonal=True, stepwise= True, suppress_warnings=True, D=10, max_D=10, error_action='ignore')
tsmodel
# Create predictions for the future, evaluate on test
preds, conf_int = tsmodel.predict(n_periods=test.shape[0], return_conf_int=True)
preds
conf_int
# Print the error:
test
preds
print("Test RMSE: %.3f" % np.sqrt(mean_squared_error(test, preds)))

#############################################################
# Plot the points and the forecasts
x_axis = np.arange(train.shape[0] + preds.shape[0])
x_years = x_axis + 1821  # Year starts at 1821
fig, axes = plt.subplots(figsize=(10, 6))
plt.plot(x_years[x_axis[:train.shape[0]]], train, alpha=0.75)