module timeseries.utils#

Short summary#

module mlinsights.timeseries.utils

Timeseries data manipulations.

source on GitHub

Functions#

function

truncated documentation

build_ts_X_y

Builds standard X, y based in the given one.

check_ts_X_y

Checks that datasets (X, y) was built with function build_ts_X_y().

Documentation#

Timeseries data manipulations.

source on GitHub

mlinsights.timeseries.utils.build_ts_X_y(model, X, y, weights=None, same_rows=False)#

Builds standard X, y based in the given one.

Parameters:
  • model – a timeseries model (BaseTimeSeries)

  • X – times series, used as features, [n_obs, n_features], X may be empty (None)

  • y – timeseries (one single vector), [n_obs]

  • weights – weights None or array [n_obs]

  • same_rows – keep the same number of rows as the original datasets, use nan when no value is available

Returns:

(X, y, weights): X is array of features [nrows, n_features + past] where nrows = n_obs + model.delay2 - model.past + 2, y is an array of targets [nrows], weights is None or array [nrows]

<<<

import numpy
from mlinsights.timeseries import build_ts_X_y
from mlinsights.timeseries.base import BaseTimeSeries

X = numpy.arange(10).reshape(5, 2)
y = numpy.arange(5) * 100
weights = numpy.arange(5) * 1000
bs = BaseTimeSeries(past=2)
nx, ny, nw = build_ts_X_y(bs, X, y, weights)
print('X=', X)
print('y=', y)
print('nx=', nx)
print('ny=', ny)

>>>

    X= [[0 1]
     [2 3]
     [4 5]
     [6 7]
     [8 9]]
    y= [  0 100 200 300 400]
    nx= [[  2   3   0 100]
     [  4   5 100 200]
     [  6   7 200 300]]
    ny= [[200]
     [300]
     [400]]

With use_all_past=True:

<<<

import numpy
from mlinsights.timeseries.base import BaseTimeSeries
from mlinsights.timeseries import build_ts_X_y

X = numpy.arange(10).reshape(5, 2)
y = numpy.arange(5) * 100
weights = numpy.arange(5) * 1000
bs = BaseTimeSeries(past=2, use_all_past=True)
nx, ny, nw = build_ts_X_y(bs, X, y, weights)
print('X=', X)
print('y=', y)
print('nx=', nx)
print('ny=', ny)

>>>

    X= [[0 1]
     [2 3]
     [4 5]
     [6 7]
     [8 9]]
    y= [  0 100 200 300 400]
    nx= [[  0   1   2   3   0 100]
     [  2   3   4   5 100 200]
     [  4   5   6   7 200 300]]
    ny= [[200]
     [300]
     [400]]

source on GitHub

mlinsights.timeseries.utils.check_ts_X_y(model, X, y)#

Checks that datasets (X, y) was built with function build_ts_X_y.

source on GitHub