omdenalore.time_series package

Submodules

omdenalore.time_series.auto_regression module

class omdenalore.time_series.auto_regression.AutoRegressive

Bases: object

Generic class to generate time-series auto regressive datasets and to plot auto-correlation function

gen_ar1_dataset(n: int = 600) numpy.ndarray

Generate AR(1) dataset

Parameters

n (int) – number of samples

Returns

ar1 dataset

gen_ar2_dataset(n: int = 600) numpy.ndarray

Generate AR(2) dataset

Parameters

n (int, optional) – number of samples

Returns

ar3 dataset

gen_ar3_dataset(n: int = 600) numpy.ndarray

Generate AR(3) dataset

Parameters

n (int, optional) – number of samples

Returns

ar3 dataset

plotds(input_signal: pandas.Series, nlag: int = 30, fig_size: Tuple[int, int] = (12, 10)) None

Function to plot signal, ACF and PACF

Parameters
  • xt (series) – input signal

  • nlag – An int or array of lag values, used on horizontal axis.

Uses np.arange(lags) when lags is an int. If not provided, lags=np.arange(len(corr)) is used. :type nlag: int, array (optional) :param fig_size: figure size :type fig_size: tuple :returns: None

omdenalore.time_series.metrics module

class omdenalore.time_series.metrics.ComputeMetrics(actual: numpy.ndarray, predicted: numpy.ndarray)

Bases: object

Generic class to evaluate & compute time series metrics between predicted values and true values

bias()

method to compute mean forecast error(or Forecast Bias)

Returns

result mean forecast error

gmae()

method to compute geometric mean absolute error

Returns

result geometric mean absolute error

gmrae(benchmark: Optional[numpy.ndarray] = None)

method to compute geometric mean relative absolute error

Parameters

benchmark (np.ndarray) – array for benchmark values

Returns

result geometric mean relative absolute error

inrse()

method to compute integral normalized root squared error

Returns

result integral normalized root squared error

maape()

method to compute mean arctangent absolute percentage error Note: result is NOT multiplied by 100

Returns

result mean arctangent absolute percentage error

mad(actual: Optional[numpy.ndarray] = None, predicted: Optional[numpy.ndarray] = None)

method to compute mean absolute deviation (it is the same as MAE)

Parameters
  • actual (np.ndarray) – array for true values

  • predicted (np.ndarray) – array for predicted values

Returns

mean absolute deviation

mae(actual: Optional[numpy.ndarray] = None, predicted: Optional[numpy.ndarray] = None)

method to compute mean absolute error

Parameters
  • actual (np.ndarray) – array for true values

  • predicted (np.ndarray) – array for predicted values

Returns

result mean absolute error

map()

method to compute mean absolute percentage error Properties:

  • Easy to interpret

  • Scale independent

  • Biased, not symmetric

  • Undefined when actual[t] == 0

Note: result is NOT multiplied by 100

Returns

result mean absolute percentage error

mase(seasonality: int = 1)

method to compute mean absolute scaled error Baseline (benchmark) is computed with naive forecasting (shifted by @seasonality)

Parameters

seasonality (int) – sample period

Returns

result mean absolute scaled error

mbrae(benchmark: Optional[numpy.ndarray] = None)

method to compute mean bounded relative absolute error

Parameters

benchmark (np.ndarray) – array for benchmark values

Returns

result mean bounded relative absolute error

mda()

method to compute mean directional accuracy

Returns

result mean directional accuracy

mdae()

method to compute median absolute error

Returns

result gmedian absolute error

mdape()

method to compute median absolute percentage error Note: result is NOT multiplied by 100

Returns

result median absolute percentage error

mdrae(benchmark: Optional[numpy.ndarray] = None)

method to compute median relative absolute error

Parameters

benchmark (np.ndarray) – array for benchmark values

Returns

result median relative absolute error

me()

method to compute mean error

Returns

result mean error

mpe()

method to compute mean percentage error

Returns

result mean percentage error

mrae(benchmark: Optional[numpy.ndarray] = None)

method to compute mean relative absolute error

Parameters

benchmark (np.ndarray) – array for benchmark values

Returns

result mean relative absolute error

mre(benchmark: Optional[numpy.ndarray] = None)

method to compute mean relative error

Parameters

benchmark (np.ndarray) – array for benchmark values

Returns

result mean relative error

mse()

method to compute mean squared error

Returns

result mean squared error

nrmse()

method to compute normalized root mean squared error

Returns

result normalized root mean squared error

r2_score()

method to compute r2 score

Returns

result r2 score

rae()

method to compute relative absolute error (aka Approximation Error)

Returns

result relative absolute error

rmdspe()

method to compute root median squared percentage error Note: result is NOT multiplied by 100

Returns

result root median squared percentage error

rmse()

method to compute root mean squared error

Returns

result root mean squared error

rmspe()

method to compute root mean squared percentage error Note: result is NOT multiplied by 100

Returns

result root mean squared percentage error

rmsse(seasonality: int = 1)

method to compute root mean squared scaled error

Parameters

seasonality (int) – sample period

Returns

result root mean squared scaled error

rrse()

method to compute root relative squared error

Returns

result root relative squared error

smape()

mehod to compute symmetric mean absolute percentage error Note: result is NOT multiplied by 100

Returns

result symmetric mean absolute percentage error

smdape()

method to compute symmetric median absolute percentage error Note: result is NOT multiplied by 100

Returns

result symmetric median absolute percentage error

std_ae()

method to compute normalized absolute error

Returns

result normalized absolute error

std_ape()

method to compute normalized absolute percentage error

Returns

result normalized absolute percentage error

umbrae(benchmark: Optional[numpy.ndarray] = None)

method to compute unscaled mean bounded relative absolute error

Parameters

benchmark (np.ndarray) – array for benchmark values

Returns

result unscaled mean bounded relative absolute error

class omdenalore.time_series.metrics.EvaluateMetrics(actual, predicted)

Bases: omdenalore.time_series.metrics.ComputeMetrics

Generic class to evaluate error metrics

evaluate(metrics=('mae', 'rmse', 'map'))

Evaluate mentioned metrics

Parameters

metrics (tuple, default=("mae", "rmse", "map")) – type of metrics to calculate

Returns

result dictionary

Note

select metrics from this list = { “mse”: mse, “rmse”: rmse, “nrmse”: nrmse, “me”: me, “mae”: mae, “mad”: mad, “gmae”: gmae, “mdae”: mdae, “mpe”: mpe, “map”: map, “mdape”: mdape, “smape”: smape, “smdape”: smdape, “maape”: maape, “mase”: mase, “std_ae”: std_ae, “std_ape”: std_ape, “rmspe”: rmspe, “rmdspe”: rmdspe, “rmsse”: rmsse, “inrse”: inrse, “rrse”: rrse, “mre”: mre, “rae”: rae, “mrae”: mrae, “mdrae”: mdrae, “gmrae”: gmrae, “mbrae”: mbrae, “umbrae”: umbrae, “mda”: mda, “bias”: bias, “r2”: r2_score, }

evaluate_all()

Evaluate all metrics from the list below

“mse”: mse, “rmse”: rmse, “nrmse”: nrmse, “me”: me, “mae”: mae, “mad”: mad, “gmae”: gmae, “mpe”: mpe, “mdae”: mdae, “map”: map, “mdape”: mdape, “smape”: smape, “smdape”: smdape, “maape”: maape, “mase”: mase, “std_ae”: std_ae, “std_ape”: std_ape, “rmspe”: rmspe, “rmdspe”: rmdspe, “rmsse”: rmsse, “inrse”: inrse, “rrse”: rrse, “mre”: mre, “rae”: rae, “mrae”: mrae, “mdrae”: mdrae, “gmrae”: gmrae, “mbrae”: mbrae, “umbrae”: umbrae, “mda”: mda, “bias”: bias, “r2”: r2_score,

Parameters
  • actual (np.ndarray) – array for true values

  • predicted (np.ndarray) – array for predict values

Returns

result dictionary

omdenalore.time_series.plots module

class omdenalore.time_series.plots.PlotMetrics

Bases: object

Generic class to plot bar chart for time-series metrics (MAE, RMSE, MAP, R2)

static bar_metrics(results_dict: dict, save_path: str, figure_size=(20, 15)) None

Plots different bar metrics

Parameters
  • results_dict – Calculated metrics

  • save_path (str) – Path to store the figures

  • figure_size (tuple 1x2) – Size of the output plots

Returns

None

Module contents