You are viewing the RapidMiner Studio documentation for version 9.8 - Check here for latest version

# Extract Coefficients (Polynomial Fit) (Time Series)

## Synopsis

This operator fits a polynomial function to time series and provides the fitted coefficients and the discrepancy as features.## Description

This operator fits a polynomial function (degree can be specified by *degree* parameter) to one or more time series.
The fitted coefficients and (if selected) the discrepancy are provided as features as an ExampleSet at the *features* output port of the operator.
The polynomial function is defined as follows (coeff: fitted coefficients; d: degree):

y = coeff_0 + coeff_1 * x + coeff_2 * x^2 + ... + coeff_d * x^d

y are the time series values, x are the index values.
If *has indices* is false, default integer indices values (starting from 0) are assumed and used to fit the polynomial function.
If the *indices attribute* is of date_time, the x values in the functions are the milliseconds since the start of the epoch (1970-01-01) of the indices values.

The features ExampleSet will contain d+1 coefficients and, if the parameter *add discrepancy* is true, the discrepancy between the fitted function and the time series data.
The discrepancy is the average squared difference between function and time series data points.

Depending on the parameter *add time series name* the ExampleSet will have one example with attributes for all combination of time series and features, or n examples, one example per time series.
In combination with the Process Windows operator, this operator can be used to calculate features of windows of time series as a preparation for a general machine learning problem.

If the time series contains invalid values (missing, positive infinity and negative infinity) the operator throws a User Error.
If the parameter *ignore invalid values* is selected, invalid values are ignored in the fitting procedure.

The operator provides the fitted function, evluated on the index values of the original time series, as additional time series at the *fitted* output port.

This operator works only on numerical time series.

## Input

- example set (Data Table)
The ExampleSet which contains the time series data as attributes.

## Output

- features (Data Table)
The ExampleSet which contains the calculated coefficients as attributes. Depending on the parameter add time series name the ExampleSet will have one example with attributes for all combination of time series and features, or n examples, one example per time series.

- original (Data Table)
The ExampleSet that was given as input is passed through without changes.

- fitted (Data Table)
This data set contains the original time series (including the indices values if has indices is true) and the fitted functions evaluated on the index values. It can be used to compare the fitted function and the original time series data.

## Parameters

- attribute_filter_type
This parameter allows you to select the filter for the time series attributes selection filter; the method you want to select the attributes which holds the time series values. Only numeric attributes can be selected as time series attributes. The different filter types are:

- all: This option selects all attributes of the ExampleSet to be time series attributes. This is the default option.
- single: This option allows the selection of a single time series attribute. The required attribute is selected by the attribute parameter.
- subset: This option allows the selection of multiple time series attributes through a list (see parameter attributes). If the meta data of the ExampleSet is known all attributes are present in the list and the required ones can easily be selected.
- regular_expression: This option allows you to specify a regular expression for the time series attribute selection. The regular expression filter is configured by the parameters regular expression, use except expression and except expression.
- value_type: This option allows selection of all the attributes of a particular type to be time series attributes. It should be noted that types are hierarchical. For example real and integer types both belong to the numeric type. The value type filter is configured by the parameters value type, use value type exception, except value type.
- block_type: This option allows the selection of all the attributes of a particular block type to be time series attributes. It should be noted that block types may be hierarchical. For example value_series_start and value_series_end block types both belong to the value_series block type. The block type filter is configured by the parameters block type, use block type exception, except block type.
- no_missing_values: This option selects all attributes of the ExampleSet as time series attributes which do not contain a missing value in any example. Attributes that have even a single missing value are not selected.
- numeric_value_filter: All numeric attributes whose examples all match a given numeric condition are selected as time series attributes. The condition is specified by the numeric condition parameter.

- attribute
The required attribute can be selected from this option. The attribute name can be selected from the drop down box of the parameter if the meta data is known.

Range: - attributes
The required attributes can be selected from this option. This opens a new window with two lists. All attributes are present in the left list. They can be shifted to the right list, which is the list of selected time series attributes.

Range: - regular_expression
Attributes whose names match this expression will be selected. The expression can be specified through the

Range:*edit and preview regular expression*menu. This menu gives a good idea of regular expressions and it also allows you to try different expressions and preview the results simultaneously. - use_except_expression
If enabled, an exception to the first regular expression can be specified. This exception is specified by the

Range:*except regular expression*parameter. - except_regular_expression
This option allows you to specify a regular expression. Attributes matching this expression will be filtered out even if they match the first expression (expression that was specified in

Range:*regular expression*parameter). - value_type
This option allows to select a type of attribute. One of the following types can be chosen: numeric, integer, real.

Range: - use_value_type_exception
If enabled, an exception to the selected type can be specified. This exception is specified by the

Range:*except value type*parameter. - except_value_type
The attributes matching this type will be removed from the final output even if they matched the before selected type, specified by the

Range:*value type*parameter. One of the following types can be selected here: numeric, integer, real. - block_type
This option allows to select a block type of attribute. One of the following types can be chosen: value_series, value_series_start, value_series_end.

Range: - use_block_type_exception
If enabled, an exception to the selected block type can be specified. This exception is specified by the

Range:*except block type*parameter. - except_block_type
The attributes matching this block type will be removed from the final output even if they matched the before selected type by the

Range:*block type*parameter. One of the following block types can be selected here: value_series, value_series_start, value_series_end. - numeric_condition
The numeric condition used by the numeric condition filter type. A numeric attribute is selected if all examples match the specified condition for this attribute. For example the numeric condition '> 6' will keep all numeric attributes having a value of greater than 6 in every example. A combination of conditions is possible: '> 6 && < 11' or '<= 5 || < 0'. But && and || cannot be used together in one numeric condition. Conditions like '(> 0 && < 2) || (>10 && < 12)' are not allowed because they use both && and ||.

Range: - invert_selection
If this parameter is set to true the selection is reversed. In that case all attributes not matching the specified condition are selected as time series attributes. Special attributes are not selected independent of the

Range:*invert selection*parameter as along as the*include special attributes*parameter is not set to true. If so the condition is also applied to the special attributes and the selection is reversed if this parameter is checked. - include_special_attributes
Special attributes are attributes with special roles. These are: id, label, prediction, cluster, weight and batch. Also custom roles can be assigned to attributes. By default special attributes are not selected as time series attributes irrespective of the filter conditions. If this parameter is set to true, special attributes are also tested against conditions specified and those attributes are selected that match the conditions.

Range: - has_indices
This parameter indicates if there is an index attribute associated with the time series. If this parameter is set to true, the index attribute has to be selected.

Range: - indices_attribute
If the parameter

Range:*has indices*is set to true, this parameter defines the associated index attribute. It can be either a date, date_time or numeric value type attribute. The attribute name can be selected from the drop down box of the parameter if the meta data is known. - degree
This parameter defines the degree of the polynomial function fitted to the time series.

Range: - add_discrepancy
If selected the discrepancy between fitted function and time series data is added as a feature. The discrepancy is the average squared difference between function and time series data point.

Range: - add_time_series_name
If this parameter is set to true the name of the time series attribute is added as a prefix to the name of the feature attributes. The resulting ExampleSet will have one example and n attributes, with n = <number of time series> x <number of features>. If this parameter is set to false, an additional attribute named

Range:*time series*is added with the name of the time series. The resulting ExampleSet will have n examples and m+1 attributes, with n = <number of time series> and m = <number of features>. The role of the*time series*attribute is set to*id*. - ignore_invalid_values
If this parameter is set to true invalid values (missing, positive and negative infinity) are ignored in the calculation of the features. If this parameter is set to false and invalid values occur in the time series, a UserError is thrown.

Range:

## Tutorial Processes

### Fitting a parabola to Lake Huron time series

In this tutorial process, a parabola (polynomial function of 2. degree) is fitted to the Lake Huron time series data set. The fitted coefficients and the discrepancy are delivered as features to the result port. Also the fitted ExampleSet is retrieved to compare the fitted function to the original data set. See the comments in the process for a detailed description.

### Using fit coefficients of linear fit as features

In this tutorial process the Extract Coefficients (Polynomial Fit) operator is used to perform a linear fit on windows of the gas price data set and the coefficients are used as features of the window. These feature data set is used to train a Random Forest model to forecast the gas price of the next day.