pyamr.core.regression package
Submodules
pyamr.core.regression.arima module
Classes:
|
- class pyamr.core.regression.arima.ARIMAWrapper(estimator=None, evaluate=True)[source]
Bases:
RegressionWrapper
Methods:
as_summary
(**kwargs)Returns a summary string (statsmodels inspired)
auto
(endog[, exog, ic, trends, max_ar, ...])Find the best model through bruteforce.
conf_int_forecast
(predictions[, alpha])Computes the out-sample confidence interval.
evaluate
([alpha])Generates a dictionary with the relevant attributes.
get_prediction
([start, end, alpha])Calls the predict function in ARIMA.
- auto(endog, exog=None, ic='bic', trends=['n', 'c'], max_ar=3, max_ma=3, max_d=1, warn='ignore', return_fits=False, converged=True, disp=0, verbose=0, **kwargs)[source]
Find the best model through bruteforce.
Note: It uses grid search through the base wrapper.
- Parameters:
endog (array-like) – The endogenous variable (aka. time series data)
exog (array-like) – The exogenous variable (by default is the time t starting in 0)
ic (string) – The information criteria which should be any of the params which are set in the wrapper (see method _init_result).
max_ar (number) – The maximum autorregresive order to inspect.
max_ma (number) – The maximum moving average order to inspect.
max_d (number) – The maximum difference to inspect.
warn (string, options = {ignore, raise}) – Whether or not to ignore the warnings raised
return_fits (bool) – Whether or not to return all the fits. If false only the best model is returned. If true all the models and the best model are returned separately.
converged (bool) – Whether or not to return only converging models. If false all models are returned. If true, only those models that converged are returned.
- conf_int_forecast(predictions, alpha=0.05)[source]
Computes the out-sample confidence interval.
- Parameters:
predictions (array-like) – The predictions done by the model.
alpha (int) – The alpha to configure the confidence interval.
- Return type:
array-like
- evaluate(alpha=0.05)[source]
Generates a dictionary with the relevant attributes.
Note
There is an issue with the method conf_int(alpha). It can receive as input parameters a pandas series or a numpy array. We are using it with numpy array as input, hence when pandas series is passed the method _init_result gives an error.
Include ref to statsmodels:Arima and statsmodels:ArimaResults.
- Parameters:
alpha (the confidence interval.)
- Returns:
dictionary
- Return type:
map with all the parameters.
- get_prediction(start=None, end=None, alpha=0.05, **kwargs)[source]
Calls the predict function in ARIMA.
Note
The confidence intervals have been implemented using the following functions
_forecast_conf_int()
and_forecast_error()
. These are implemented instatsmodels.ts.arima_model.ARIMAResults
. As such, it produces the same confidence intervals than the methodplot_predict()
.Note
The parameter start refers to the original series. As such, if the series has been differenced (e.g. d=1) the first observation has been lost. In those cases, start has to be greater or equal to d.
Todo
Review the predictions when dynamic is set to true.
Review the confidence intervals (in and out sample)
Review the prediction intervals.
- Parameters:
start (int (optional)) – The time t to start the prediction
end (int (optional)) – The time t to end the prediction
dynamic (bool) – The dynamic keyword affects in-sample prediction. If dynamic is false then the in-sample lagged values are used for prediction. if dynamic is true, then in-sample forecasts are used in place of lagged dependent variables. The first forecasted value is start.
alpha (float) – The alpha value when creating the norm point percent function to compute the confidence intervals for the forecast predictions.
typ (string-like, options = {linear, levels}) – Wether to predict the original levels (levels) or predict in terms of the differenced endogenous variables.
- Return type:
matrix
pyamr.core.regression.pyarima module
Classes:
|
- class pyamr.core.regression.pyarima.PyramidWrapper(**kwargs)[source]
Bases:
BaseRegressionWrapper
Methods:
as_summary
(**kwargs)This method displays the summary.
auto
(**kwargs)This method finds the best arima.
fit
(**kwargs)This method fits the specified arima model.
from_instance
(arima, **kwargs)This method constructs a PyramidWrapper object from pyramid.ARIMA
get_prediction
(**kwargs)- fit(**kwargs)[source]
This method fits the specified arima model.
- Parameters:
endog
exog
missing
hasconst
- Returns:
object
- Return type:
A PyramidWrapper object.
pyamr.core.regression.pyarima2 module
Classes:
|
- class pyamr.core.regression.pyarima2.PyramidWrapper(estimator=None, evaluate=True)[source]
Bases:
RegressionWrapper
Methods:
as_summary
(**kwargs)This method displays the summary.
auto
(**kwargs)This method finds the best arima.
evaluate
([alpha])This method set all the variables into this class.
from_instance
(arima, **kwargs)This method constructs a PyramidWrapper object from pyramid.ARIMA
get_prediction
([start, end, alpha])resid
()Get the residual
- evaluate(alpha=0.05)[source]
This method set all the variables into this class.
@see: statsmodels.Arima @see: statsmodels.ArimaResults
- Parameters:
alpha
- Return type:
series
pyamr.core.regression.sarimax module
Classes:
|
Description |
- class pyamr.core.regression.sarimax.SARIMAXWrapper(estimator=None, evaluate=True)[source]
Bases:
RegressionWrapper
Description
Methods:
as_summary
(**kwargs)This method creates a summary string.
auto
(endog[, exog, ic, max_ar, max_ma, ...])This method finds the best arima through bruteforce.
evaluate
([alpha])This method creates a dictioanry with the relevant parameters.
get_prediction
([start, end, alpha])This method calls the get prediction function in ARIMA.
load
(**kwargs)This method loads the information.
save
(**kwargs)This method saves the information.
- auto(endog, exog=None, ic='bic', max_ar=3, max_ma=3, max_d=1, max_P=0, max_D=0, max_Q=0, list_s=[12], warn='ignore', trends=['n', 'c', 't', 'ct'], return_fits=False, verbose=0, converged=True, **kwargs)[source]
This method finds the best arima through bruteforce.
Note: It uses grid search through the base wrapper.
- Parameters:
endog (array-like) – The endogenous variable (aka. time series data)
exog (array-like) – The exogenous variable (by default is the time t starting in 0)
ic (string) – The information criteria which should be any of the params which are set in the wrapper (see method _init_result).
max_ar (number) – The maximum autorregresive order to inspect.
max_ma (number) – The maximum moving average order to inspect.
max_d (number) – The maximum difference to inspect.
max_P (number)
max_D (number)
max_Q (number)
list_s (array-like)
warn (string, options = {ignore, raise}) – Whether or not to ignore the warnings raised
return_fits (bool) – Whether or not to return all the fits. If false only the best model is returned. If true all the models and the best model are returned separately.
converged (bool) – Whether or not to return only converging models. If false all models are returned. If true, only those models that converged are returned.
- evaluate(alpha=0.05)[source]
This method creates a dictioanry with the relevant parameters.
@see: statsmodels.Sarimax @see: statsmodels.SarimaxResults
- Parameters:
alpha (significance level)
- Returns:
dictionary
- Return type:
dictionary with the parameters.
- get_prediction(start=None, end=None, alpha=0.05, **kwargs)[source]
This method calls the get prediction function in ARIMA.
- Parameters:
start (int (optional)) – The time t to start the prediction
end (int (optional)) – The time t to end the prediction
dynamic (bool) – The dynamic keyword affects in-sample prediction. If dynamic is false then the in-sample lagged values are used for prediction. if dynamic is true, then in-sample forecasts are used in place of lagged dependent variables. The first forecasted value is start.
alpha (float) – The alpha value when creating the norm point percent function to compute the confidence intervals for the forecast predictions.
typ (string-like, options = {linear, levels}) – Wether to predict the original levels (levels) or predict in terms of the differenced endogenous variables.
- Return type:
matrix
pyamr.core.regression.theilsens module
Classes:
|
- class pyamr.core.regression.theilsens.TheilSensWrapper(**kwargs)[source]
Bases:
BaseRegressionWrapper
Methods:
as_summary
([alpha])This method displays the summary.
fit
(**kwargs)This method....
get_prediction
([exog, start, end])This method...
pyamr.core.regression.wbase module
Classes:
|
- class pyamr.core.regression.wbase.BaseWrapper(**kwargs)[source]
Bases:
object
Methods:
as_series
([flabel, label])This method returns a series with all the information.
This method displays the final summary.
attrs
()This method returns all the defined attributes as tuples.
fargs
(kwargs, function)This method returns elements in kwargs which are function inputs.
fit
(**kwargs)This method performs the fit.
from_list_dataframe
(wrapper_list, **kwargs)This methods creates a dataframe summary from a list.
grid_search
(grid_params)This method computes grid search.
grid_search_dataframe
(grid_params, **kwargs)This method computes grid search and stores results in a dataframe.
load
(fname)This method loads the wrapper.
methods
()This method returns all the defined methods as tuples.
save
(fname)This method saves the wrapper.
- as_series(flabel=True, label=None)[source]
This method returns a series with all the information.
- Parameters:
label (label to concatenate to index name (e.g. trend to label-trend).)
- Returns:
series
- Return type:
pandas series with the results, configuration and model.
- from_list_dataframe(wrapper_list, **kwargs)[source]
This methods creates a dataframe summary from a list.
- Parameters:
wrapper_list (list with wrapper objects.)
flabel (if include the class _name in the index.)
- Returns:
summary
- Return type:
pandas dataframe.
- grid_search(grid_params)[source]
This method computes grid search.
It creates all the possible combinations combining the arguments passed. Such arguments should be for the constructor and the fit methods. The results are stored in an array with the corresponding wrapper instances.
Notes: The wrappers need to have the method fit implemented.
- Parameters:
con_kwargs (arguments to be passed to the constructor method.)
fit_kwargs (arguments to be passed to the fit method.)
- Returns:
summary
- Return type:
summary with all the elements.
- grid_search_dataframe(grid_params, **kwargs)[source]
This method computes grid search and stores results in a dataframe.
- Parameters:
con_kwargs (arguments to be passed to the constructor method.)
fit_kwargs (arguments to be passed to the fit method.)
- Returns:
summary
- Return type:
summary with all the elements.
pyamr.core.regression.wls module
Classes:
|
|
|
The description... |
- class pyamr.core.regression.wls.PredictionResult(mean, cilo, ciup, pstd, pilo, piup, time, nobs, endog)[source]
Bases:
object
- class pyamr.core.regression.wls.WLSWrapper(estimator=None, evaluate=True)[source]
Bases:
RegressionWrapper
The description…
Methods:
as_summary
(**kwargs)This method creates a summary string.
evaluate
([alpha])This method set all the variables into this class.
fit
(endog[, exog, trend, weights, W])This method computes the WLS.
get_prediction
([start, end, alpha])This method predicts using the model.
line
(x)This method returns arrays to plot line and confidence intervals.
pred_int
([start, end])This method computes the prediction intervals
- evaluate(alpha=0.05)[source]
This method set all the variables into this class.
- Notes:
if instead of having the attribute series it is desired to set each element of the series as an attribute, just used the following statement: setattr(self, name, value).
Note the difference between the resid and wresid since they will also have different statistical properties. Furthermore, there is a vector with normalized residuals resid_pearson.
@see: statsmodels.WLS @see: pyAMR.core.regression.RegressionResultsWrapper
- Parameters:
alpha (the confidence interval)
- Returns:
dictionary
- Return type:
map with all the parameters.
- fit(endog, exog=None, trend='n', weights=None, W=None, **kwargs)[source]
This method computes the WLS.
@see statsmodels.regression.linear_model.WLS
- Parameters:
endog (array-like) – The endogenous variable (aka. time series data)
exog (array-like) – The exogenous variable (by default is the time t starting in 0)
trend (str-like, options = {c, n}) – Wether to add a constant or not.
weights (array-like (optional)) – The weights for the weighted least square regression. If weights and W are both not None, the W instance will be used to transform the weights variables.
W (object-like (optional)) – The instance to transform the weights. It must implement the function ‘weights’.
kwargs (dict-like) – The rest of the arguments to pass to the __init__ and fit methods of the class statsmodels.WLS (see xxx)
- Returns:
object
- Return type:
OLSWrapper object.
- get_prediction(start=None, end=None, alpha=0.05, **kwargs)[source]
This method predicts using the model.
Todo
Note that wls_predict_std has weights (those used in WLS) as an input parameter. However, these are not passed to the function. Those weights are available for insample predictions but not for forecasting.
- Parameters:
start (int (optional)) – The time t to start the prediction
end (int (optional)) – The time t to end the prediction
kwargs – The arguments to pass to the method get_prediction of the class statsmodels.WLS (see xxx)
- Return type:
time, prediction mean, prediction confidence interval
pyamr.core.regression.wlsarma module
Classes:
|
- class pyamr.core.regression.wlsarma.WLSARMAWrapper(**kwargs)[source]
Bases:
BaseRegressionWrapper
Methods:
as_summary
(**kwargs)This method displays the summary.
fit
(endog[, exog, weights, wls_kwargs, ...])This method...
get_prediction
([start, end, ptype])This method computes the prediction.
- fit(endog, exog=None, weights=None, wls_kwargs={}, arima_kwargs=None, sarimax_kwargs=None, **kwargs)[source]
This method…
- Parameters:
endog
exog
wls_kwargs
arima_kwargs
sarimax_kwargs
kwargs
- get_prediction(start=None, end=None, ptype='combined', **kwargs)[source]
This method computes the prediction.
Note: Correct for ARIMA. The arima is trained with n samples (e.g. 24) and then we ask for start=50 and end=74 hance for some reason arima becomes crazy and return a larger array. Therefore, we predict for indices None (begining) till the maxium number to predict which is fshape-start.
- Parameters:
start (start of prediction (as in wls))
end (end of preediction (as in wls))
type (string (combined, wls, arma))
pyamr.core.regression.wreg module
Classes:
|
Description... |
- class pyamr.core.regression.wreg.RegressionWrapper(estimator=None, evaluate=True)[source]
Bases:
BaseWrapper
Description…
Methods:
conf_int_insample
(predictions[, alpha])Computes the in-sample confidence interval.
fit
(**kwargs)This method performs the fit.
resid
()Get the residual
- conf_int_insample(predictions, alpha=0.05)[source]
Computes the in-sample confidence interval.
- Parameters:
predictions (array-like) – The predictions done by the model.
alpha (int) – The alpha to configure the confidence interval.
- Return type:
array-like
pyamr.core.regression.wregression module
Classes:
|
- class pyamr.core.regression.wregression.BaseRegressionWrapper(**kwargs)[source]
Bases:
BaseWrapper
Methods:
conf_int_insample
(forecast[, resid, alpha])This function computes a basic confidence interval.