Orange3-Timeseries Documentation: Release
Orange3-Timeseries Documentation: Release
Orange3-Timeseries Documentation: Release
Release
1 Widgets 1
2 Python Scripting 29
i
ii
CHAPTER 1
Widgets
1.1.1 Signals
Outputs
• Time series
Time series table of open, high, low, close (OHLC) prices, volume and adjusted close price.
1.1.2 Description
This widget fetches historical stock market data from Yahoo Finance and outputs it as a time series data table.
1
Orange3-Timeseries Documentation, Release
1. Stock (e.g. GOOG) or index (e.g. ^DJI) symbol you are interested in.
2. Date range you are interested in.
3. Desired resolution of the time series. Can be one of: daily, weekly, monthly, or dividends. The last option
outputs a table of dates when dividends were issued, along with their respective dividend amounts.
1.1.3 Example
Since the output data type is inherently a Table, you can connect it to wherever data table is expected.
1.2 As Timeseries
2 Chapter 1. Widgets
Orange3-Timeseries Documentation, Release
1.2.1 Signals
Inputs
• Data
Any data table.
Outputs
• Time series
Data table reiterpreted as time series.
1.2.2 Description
This widget reinterprets any data table as a time series, so it can be used with the rest of the widgets in this add-on.
In the widget, you can set which data attribute represents the time variable.
1. The time attribute, the values of which imply measurements order and spacing. This can be any continuous
attribute.
2. Alternatively, you can specify that the time series sequence is implied by instance order.
1.2.3 Example
The input to this widget comes from any data-emitting widget, e.g. File widget. Note, whenever you do some
processing with Orange core widgets, like the Select Columns widget, you need to re-apply the conversion into time
series with this widget.
1.3. Interpolate 3
Orange3-Timeseries Documentation, Release
1.3 Interpolate
1.3.1 Signals
Inputs
• Time series
Time series as output by As Timeseries widget.
Outputs
• Time series
The input time series but preset with chosen default interpolation method for when algorithms require interpo-
lated time series (without missing values).
• Interpolated time series
The input time series with any missing values interpolated according to chosen interpolation method.
1.3.2 Description
Most time series algorithms assume, you don’t have any missing values in your data. In this widget, you can chose
the interpolation method to impute the missing values with. By default, it’s linear interpolation (fast and reasonable
default).
4 Chapter 1. Widgets
Orange3-Timeseries Documentation, Release
1. Interpolation type. You can select one of linear, cubic spline, nearest, or mean interpolation. Linear interpo-
lation replaces missing values with linearly-spaced values between the two nearest defined data points. Spline
interpolation fits a cubic polynomial to the points around missing values. This is a painfully slow method that
usually gives best results. Nearest interpolation replaces missing values with the previous defined value. Mean
interpolation replaces missing values with the series mean.
2. Select Multi-variate interpolation to interpolate the whole series table as a two-dimensional plane instead of
as separate single-dimensional series.
Note: Missing values on the series’ end points (head and tail) are always interpolated using nearest method.
Note: Unless the interpolation method is set to nearest, discrete time series (i.e. sequences) are always imputed with
the series mode (most frequent value).
1.3.3 Example
Pass a time series with missing values in, get interpolated time series out.
1.4 Aggregate
1.4.1 Signals
Inputs
• Time series
Time series as output by As Timeseries widget.
Outputs
• Time series
Aggregated time series.
1.4.2 Description
1. Interval to aggregate the time series by. Options are: second, minute, hour, say, week, month, or year.
2. Aggregation function for each of the time series in the table.
Note: Discrete variables (sequences) can only be aggregated using mode (i.e. most frequent value), whereas string
variables can only be aggregated using string concatenation.
1.4. Aggregate 5
Orange3-Timeseries Documentation, Release
6 Chapter 1. Widgets
Orange3-Timeseries Documentation, Release
Moving Transform
1.5 Difference
Make the time series stationary by replacing it with 1st or 2nd order discrete difference along its values.
1.5.1 Signals
Inputs
• Time series
Time series as output by As Timeseries widget.
Outputs
• Time series
Differenced time series.
1.5. Difference 7
Orange3-Timeseries Documentation, Release
1.5.2 Description
Note: To integrate the differences back into the original series (e.g. the forecasts), use the Moving Transform widget.
Decompose the time series into seasonal, trend, and residual components.
8 Chapter 1. Widgets
Orange3-Timeseries Documentation, Release
1.6.1 Signals
Inputs
• Time series
Time series as output by As Timeseries widget.
Outputs
• Time series
Original time series with some additional columns: seasonal component, trend component, residual component,
and seasonally adjusted time series.
1.6.2 Description
Moving Transform
1.6.4 Examples
Apply rolling window functions to the time series. Use this widget to get a series’ mean.
10 Chapter 1. Widgets
Orange3-Timeseries Documentation, Release
1.7.1 Signals
Inputs
• Time series
Time series as output by As Timeseries widget.
Outputs
• Time series
The input time series with added series transformations.
1.7.2 Description
In this widget, you define what aggregation functions to run over the time series and with what window sizes.
5. Aggregation function to aggregate the values in the window with. Options are: mean, sum, max, min, median,
mode, standard deviation, variance, product, linearly-weighted moving average, exponential moving average,
harmonic mean, geometric mean, non-zero count, cumulative sum, and cumulative product.
6. Select Non-overlapping windows options if you don’t want the moving windows to overlap but instead be placed
side-to-side with zero intersection.
7. In the case of non-overlapping windows, define the fixed window width (overrides and widths set in (4).
Seasonal Adjustment
1.7.4 Example
To get a 5-day moving average, we can use a rolling window with mean aggregation.
To integrate a differenced time series, use Cumulative sum aggregation over a window wide enough to grasp the whole
series.
1.8 Correlogram
1.8.1 Signals
Inputs
• Time series
Time series as output by As Timeseries widget.
1.8.2 Description
In this widget, you can visualize the autocorrelation coefficients for selected time series.
1. Select the series to calculate autocorrelation for.
2. See the autocorrelation coefficients.
3. Choose to calculate the coefficients using partial autocorrelation function (PACF) instead.
4. Choose to plot the 95% significance interval (dotted horizontal line). Coefficients that reach outside of this
interval might be significant.
Periodogram
12 Chapter 1. Widgets
Orange3-Timeseries Documentation, Release
1.8. Correlogram 13
Orange3-Timeseries Documentation, Release
14 Chapter 1. Widgets
Orange3-Timeseries Documentation, Release
1.9 Periodogram
Visualize time series’ cycles, seasonality, periodicity, and most significant periods.
1.9.1 Signals
Inputs
• Time series
Time series as output by As Timeseries widget.
1.9.2 Description
In this widget, you can visualize the most significant periods of the time series.
1. Select the series to calculate the periodogram for.
2. See the periods and their respective relative power spectral density estimates.
1.9. Periodogram 15
Orange3-Timeseries Documentation, Release
Correlogram
Visualize time series’ sequence and progression in the most basic time series visualization imaginable.
1.10.1 Signals
Inputs
• Time series
Time series as output by As Timeseries widget.
• Forecast
Time series forecast as output by one of the models (like VAR or ARIMA).
1.10.2 Description
16 Chapter 1. Widgets
Orange3-Timeseries Documentation, Release
1.10.3 Example
Attach the model’s forecast to the Forecast input signal to preview it. The forecast is drawn with a dotted line and the
confidence intervals as an ranged area.
1.11 Spiralogram
1.11.1 Signals
Inputs
• Time series
Time series as output by As Timeseries widget.
1.11.2 Description
In this widget, you can visualize the autocorrelation coefficients for selected time series.
1.11. Spiralogram 17
Orange3-Timeseries Documentation, Release
18 Chapter 1. Widgets
Orange3-Timeseries Documentation, Release
1. Unit of the vertical axis. Options are: years, months, or days (as present in the series); months of year, days of
week, days of month, days of year, weeks of year, weeks of month, hours of day, minutes of hour.
2. Unit of the radial axis (options are the same as for (1)).
3. Aggregation function. The series is aggregated on intervals selected in (1) and (2).
4. Select the series to include.
Aggregate
1.11.4 Example
In the example image above that shows traffic for select French highways, we see a strong seasonal pattern (high
summer) and somewhat of an anomaly on July 1992. In this month, there was an important trucker strike in protest of
new road laws.
1.12.1 Signals
Inputs
• Time series
Time series as output by As Timeseries widget.
• Exogenous data
Time series of additional independent variables that can be used in an ARIMAX model.
Outputs
1.12.2 Description
Using this widget, you can model the time series with ARIMA model.
1. Model’s name. By default, the name is derived from the model and its parameters.
2. ARIMA p, d, q parameters.
3. Use exogenous data. Using this option, you need to connect additional series on the Exogenous data input
signal.
4. Number of forecast steps the model should output, along with the desired confidence intervals values at each
step.
1.12.4 Example
20 Chapter 1. Widgets
Orange3-Timeseries Documentation, Release
22 Chapter 1. Widgets
Orange3-Timeseries Documentation, Release
1.13.1 Signals
Inputs
• Time series
Time series as output by As Timeseries widget.
Outputs
1.13.2 Description
Using this widget, you can model the time series using VAR model.
1. Model’s name. By default, the name is derived from the model and its parameters.
2. Desired model order (number of parameters).
3. If other than None, optimize the number of model parameters (up to the value selected in (2)) with the selected
information criterion (one of: AIC, BIC, HQIC, FPE, or a mix thereof).
4. Choose this option to add additional “trend” columns to the data. If Constant, a single column of ones is added.
If Constant and linear, a column of ones and a column of linearly increasing numbers are added. If Constant,
linear and quadratic, an additional column of quadratics is added.
5. Number of forecast steps the model should output, along with the desired confidence intervals values at each
step.
1.13.4 Example
Evaluate different time series’ models by comparing the errors they make in terms of: root mean squared error (RMSE),
median absolute error (MAE), mean absolute percent error (MAPE), prediction of change in direction (POCID),
coefficient of determination (R²), Akaike information criterion (AIC), and Bayesian information criterion (BIC).
24 Chapter 1. Widgets
Orange3-Timeseries Documentation, Release
1.14.1 Signals
Inputs
• Time series
Time series as output by As Timeseries widget.
• Time series model (multiple)
The time series model to evaluate (e.g. VAR or ARIMA).
1.14.2 Description
Note: This slide (source) shows how cross validation on time series is performed. In this case, the number of folds
(1) is 10 and the number of forecast steps in each fold (2) is 1.
Note: In-sample errors are the errors calculated on the training data itself. A stable model is one where in-sample
errors and out-of-sample errors don’t differ significantly.
Test if one time series Granger-causes (i.e. can be an indicator of) another time series.
26 Chapter 1. Widgets
Orange3-Timeseries Documentation, Release
1.15.1 Signals
Inputs
• Time series
Time series as output by As Timeseries widget.
1.15.2 Description
This widgets performs a series of statistical tests to determine the series that cause other series so we can use the
former to forecast the latter.
Tip: The time series that Granger-cause the series you are interested in are good candidates to have in the same VAR
model.
Warning: Even if one series is said to Granger-cause another, this doesn’t mean there really exists a causal
relationship. Mind your conclusions.
28 Chapter 1. Widgets
CHAPTER 2
Python Scripting
2.1.1 Periodicity
2.1.2 Autocorrelation
29
Orange3-Timeseries Documentation, Release
[ 48. , 0.19895185]])
>>> pacf = partial_autocorrelation(data.Y)
>>> pacf[:4]
array([[ 9. , 0.23248854],
[ 13. , -0.53969124],
[ 25. , -0.16274616],
[ 40. , -0.08833969]])
2.1.3 Interpolation
You can interpolate those values with one of supported interpolation methods using
interpolate_timeseries() function:
>>> interpolated = interpolate_timeseries(data, method='cubic')
>>> interpolated[7:11].Y
array([ 151.22663433, 146.80661022, 137.77326894, 127.15995178])
>>> data = interpolated
To decompose the time series into trend, seasonal and residual components, use seasonal_decompose() func-
tion:
>>> passengers = Timeseries(Domain(['Air passengers'], source=data.domain), data)
>>> decomposed = seasonal_decompose(passengers, model='multiplicative', period=12)
>>> decomposed.domain
[Air passengers (season. adj.), Air passengers (seasonal), Air passengers (trend), Air passengers (re
To use this decomposed time series effectively, we just have to add back the time variable that was stripped in the first
step above:
>>> ts = Timeseries(Timeseries.concatenate((data, decomposed)))
>>> ts.time_variable = data.time_variable
It’s easy enough to apply moving windows transforms over any raw data in Python. In Orange3-Timeseries, you can
use moving_transform() function. It accepts a time series object and a transform specification (list of tuples
(Variable, window length, aggregation function)). For example:
>>> spec = [(data.domain['Air passengers'], 10, np.nanmean), ] # Just 10-year SMA
>>> transformed = moving_transform(data, spec)
>>> transformed.domain
[Month, Air passengers (10; nanmean) | Air passengers]
>>> transformed
[[1949-01-01, 112.000 | 112.000],
[1949-02-01, 115.000 | 118.000],
There are, as of yet, two models available: ARIMA and VAR. Both models have a common interface, so the usage of
one is similar to the other. Let’s look at an example. The data we model must have defined a class variable:
>>> data = Timeseries('airpassengers')
>>> data.domain
[Month | Air passengers]
>>> data.domain.class_var
ContinuousVariable(name='Air passengers', number_of_decimals=3)
We define the model with its parameters (see the reference for what arguments each model accepts):
>>> model = ARIMA((2, 1, 1))
After fitting, we can get the forecast along with desired confidence intervals:
>>> forecast, ci95_low, ci95_high = model.predict(steps=10, alpha=.05)
We can examine model’s fitted values and residuals with appropriately-named methods:
>>> model.fittedvalues(as_table=False)
array([ 114.7, 121.7, ..., 440.4, 386.8])
>>> model.residuals(as_table=False)
array([ 3.3, 10.3, ..., -50.4, 45.2])
MAPE 0.08
POCID 58.45
R2 0.95
RMSE 27.06
Finally, one should more robustly evaluate their models using cross validation. An example, edited for some clarity:
>>> models = [ARIMA((1, 1, 0)), ARIMA((2, 1, 2)), VAR(1), VAR(3)]
>>> model_evaluation(data, models, n_folds=10, forecast_steps=3)
[['Model', 'RMSE', 'MAE', 'MAPE', 'POCID', 'R²', 'AIC', 'BIC'],
['ARIMA(1,1,0)', 47.318, 36.803, 0.093, 68.965, 0.625, 1059.3, 1067.4],
['ARIMA(1,1,0) (in-sample)', 32.040, 20.340, 0.089, 58.450, 0.927, 1403.4, 1412.3],
['ARIMA(2,1,2)', 44.659, 28.332, 0.075, 72.413, 0.666, 1032.8, 1049.2],
['ARIMA(2,1,2) (in-sample)', 25.057, 16.159, 0.070, 59.859, 0.955, 1344.0, 1361.8],
['VAR(1)', 63.185, 45.553, 0.118, 68.965, 0.332, 28.704, 28.849],
['VAR(1) (in-sample)', 31.316, 19.001, 0.084, 54.929, 0.930, 29.131, 29.255],
['VAR(3)', 46.210, 28.526, 0.085, 82.758, 0.643, 28.140, 28.482],
['VAR(3) (in-sample)', 25.642, 18.010, 0.072, 61.428, 0.953, 28.406, 28.698]]
functions.r2(true, pred)
Coefficient of determination (R²)
functions.rmse(true, pred)
Root mean squared error
functions.mape(true, pred)
Mean absolute percentage error
functions.mae(true, pred)
Median absolute error
functions.pocid(true, pred)
Prediction on change of direction
functions.periodogram(x, *args, detrend=’diff’, **kwargs)
Return periodogram of signal x.
Parameters
• x (array_like) – A 1D signal.
• detrend (’diff’ or False or int) – Remove trend from x. If int, fit and subtract
a polynomial of this order. See also: statsmodels.tsa.detrend.
• kwargs (args,) – As accepted by scipy.signal.periodogram.
Returns
• periods (array_like) – The periods at which the spectral density is calculated.
• pgram (array_like) – Power spectral density of x.
functions.periodogram_nonequispaced(times, x, *, freqs=None, period_low=None, pe-
riod_high=None, n_periods=1000, detrend=’linear’)
Compute the Lomb-Scargle periodogram for non-equispaced timeseries.
Parameters
• times (array_like) – Sample times.
• x (array_like) – A 1D signal.
• freqs (array_like, optional) – Angular frequencies for output periodogram.
• period_low (float) – If freqs not provided, the lowest period for which to look for
periodicity. Defaults to 5th percentile of time difference between observations.
• period_high (float) – If freqs not provided, the highest period for which to look
for periodicity. Defaults to 80th percentile of time difference of observations, or 200*pe-
riod_low, whichever is larger.
• n_periods (int) – Number of periods between period_low and period_high to try.
• detrend (’diff’ or False or int) – Remove trend from x. If int, fit and subtract
a polynomial of this order. See also: statsmodels.tsa.detrend.
Returns
• periods (array_like) – The periods at which the spectral density is calculated.
• pgram (array_like) – Lomb-Scargle periodogram.
Notes
Returns res – Each internal list is [lag, antecedent, consequent] where lag is the minimum lag at
which antecedent feature in data is Granger-causal for the consequent feature in data.
Return type list of lists
functions.moving_transform(data, spec, fixed_wlen=0)
Return data transformed according to spec.
Parameters
• data (Timeseries) – A table with features to transform.
• spec (list of lists) – A list of lists [feature:Variable, window_length:int, func-
tion:callable].
• fixed_wlen (int) – If not 0, then window_length in spec is disregarded and this length
is used. Also the windows don’t shift by one but instead align themselves side by side.
Returns transformed – A table of original data its transformations.
Return type Timeseries
functions.model_evaluation(data, models, n_folds, forecast_steps, *, callback=None)
Evaluate models on data.
Parameters
• data (Timeseries) – The timeseries to model. Must have a class variable that is used
for prediction and scoring.
• models (list) – List of models (objects with fit() and predict() methods) to try.
• n_folds (int) – Number of iterations.
• forecast_steps (int) – Number of forecast steps at each iteraction.
• callback (callable, optional) – Optional argument-less callback to call after
each iteration.
Returns results – A table with horizontal and vertical headers and results. Print it to see it.
Return type list of lists
• genindex
• modindex
• search
37
Orange3-Timeseries Documentation, Release
f
functions, 32
39
Orange3-Timeseries Documentation, Release
A
autocorrelation() (in module functions), 33
F
functions (module), 32
G
granger_causality() (in module functions), 34
I
interpolate_timeseries() (in module functions), 34
M
mae() (in module functions), 32
mape() (in module functions), 32
model_evaluation() (in module functions), 35
moving_transform() (in module functions), 35
P
partial_autocorrelation() (in module functions), 33
periodogram() (in module functions), 32
periodogram_nonequispaced() (in module functions), 33
pocid() (in module functions), 32
R
r2() (in module functions), 32
rmse() (in module functions), 32
S
seasonal_decompose() (in module functions), 34
41