Luego de de esta prolongada compilación de información solucionamos esta traba que pueden tener algunos de nuestros lectores. Te brindamos la solución y deseamos resultarte de gran apoyo.
Ejemplo 1: ar model python
# create and evaluate an updated autoregressive modelfrom pandas import read_csv
from matplotlib import pyplot
from statsmodels.tsa.ar_model import AutoReg
from sklearn.metrics import mean_squared_error
from math import sqrt
# load dataset
series = read_csv('daily-minimum-temperatures.csv', header=0, index_col=0, parse_dates=True, squeeze=True)# split dataset
X = series.values
train, test = X[1:len(X)-7], X[len(X)-7:]# train autoregression
window =29
model = AutoReg(train, lags=29)
model_fit = model.fit()
coef = model_fit.params
# walk forward over time steps in test
history = train[len(train)-window:]
history =[history[i]for i inrange(len(history))]
predictions =list()for t inrange(len(test)):
length =len(history)
lag =[history[i]for i inrange(length-window,length)]
yhat = coef[0]for d inrange(window):
yhat += coef[d+1]* lag[window-d-1]
obs = test[t]
predictions.append(yhat)
history.append(obs)print('predicted=%f, expected=%f'%(yhat, obs))
rmse = sqrt(mean_squared_error(test, predictions))print('Test RMSE: %.3f'% rmse)# plot
pyplot.plot(test)
pyplot.plot(predictions, color='red')
pyplot.show()
Ejemplo 2: ar model python
# create and evaluate a static autoregressive modelfrom pandas import read_csv
from matplotlib import pyplot
from statsmodels.tsa.ar_model import AutoReg
from sklearn.metrics import mean_squared_error
from math import sqrt
# load dataset
series = read_csv('daily-minimum-temperatures.csv', header=0, index_col=0, parse_dates=True, squeeze=True)# split dataset
X = series.values
train, test = X[1:len(X)-7], X[len(X)-7:]# train autoregression
model = AutoReg(train, lags=29)
model_fit = model.fit()print('Coefficients: %s'% model_fit.params)# make predictions
predictions = model_fit.predict(start=len(train), end=len(train)+len(test)-1, dynamic=False)for i inrange(len(predictions)):print('predicted=%f, expected=%f'%(predictions[i], test[i]))
rmse = sqrt(mean_squared_error(test, predictions))print('Test RMSE: %.3f'% rmse)# plot results
pyplot.plot(test)
pyplot.plot(predictions, color='red')
pyplot.show()
Si eres capaz, puedes dejar un artículo acerca de qué le añadirías a este enunciado.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)