| |
Methods defined here:
- __init__(self, data=None, target_columns=None, alpha=0.1, start_rows=2, window_size=10, include_first=False, mavgtype='C', data_partition_column=None, data_order_column=None)
- DESCRIPTION:
The MovingAverage function calculates the moving average of the
target columns based on the moving average types ("mvgtype").
Possible moving average types:
'C' Cumulative moving average.
'E' Exponential moving average.
'M' Modified moving average.
'S' Simple moving average.
'T' Triangular moving average.
'W' Weighted moving average.
Note: This function is only available when teradataml is connected
to Vantage 1.1 or later versions.
PARAMETERS:
data:
Required Argument.
Specifies the name of the teradataml DataFrame that contains the
columns.
data_partition_column:
Required Argument.
Specifies Partition By columns for data.
Values to this argument can be provided as a list, if multiple
columns are used for partition.
Types: str OR list of Strings (str)
data_order_column:
Required Argument.
Specifies Order By columns for data.
Values to this argument can be provided as a list, if multiple
columns are used for ordering.
Types: str OR list of Strings (str)
target_columns:
Optional Argument.
Specifies the input column names for which the moving average is to
be computed. If you omit this argument, then the function copies
every input column to the output teradataml DataFrame but does not
compute moving average.
Types: str OR list of Strings (str)
alpha:
Optional Argument.
Specifies the damping factor, a value in the range [0, 1], which
represents a percentage in the range [0, 100]. For example, if alpha
is 0.2, then the damping factor is 20%. A higher alpha discounts
older observations faster. Only used if "mavgtype" is E.
For other moving average types this value will be ignored.
Default Value: 0.1
Types: float
start_rows:
Optional Argument.
Specifies the number of rows at the beginning of the time series that
the function skips before it begins the calculation of the
exponential moving average. The function uses the arithmetic average
of these rows as the initial value of the exponential moving average.
Only used if "mavgtype" is E. For other moving average types
this value will be ignored.
Default Value: 2
Types: int
window_size:
Optional Argument.
Specifies the number of previous values to include in the computation
of the moving average if "mavgtype" is M, S, T, and W.
For other moving average types this value will be ignored.
Default Value: 10
Types: int
include_first:
Optional Argument.
Specifies whether the first START_ROWS rows should be included in the
output or not. Only used if "mavgtype" is S, M, W, E, T.
For cumulative moving average types this value will be ignored.
Default Value: False
Types: bool
mavgtype:
Optional Argument.
Specify the moving average type that needs to be used for computing
moving averages of "target_columns".
Following are the different type of averages calculated by MovingAverage function:
S: The MovingAverage function computes the simple moving average of points in a
series.
W: The MovingAverage function computes the weighted moving average the average of
points in a time series, applying weights to older values. The
weights for the older values decrease arithmetically.
E: The MovingAverage function computes the exponential moving average
of the points in a time series, exponentially decreasing the
weights of older values.
C: The MovingAverage function computes the cumulative moving average of a value
from the beginning of a series.
M: The MovingAverage function computes moving average of points in series.
T: The MovingAverage function computes double-smoothed average of points in series.
Default Value: "C"
Permitted Values: C, S, M, W, E, T
Types: str
RETURNS:
Instance of MovingAverage.
Output teradataml DataFrames can be accessed using attribute
references, such as MovingAverageObj.<attribute_name>.
Output teradataml DataFrame attribute name is:
result
RAISES:
TeradataMlException
EXAMPLES:
# Load the data to run the example.
load_example_data("movavg", "ibm_stock")
# Create teradataml DataFrame objects.
ibm_stock = DataFrame.from_table("ibm_stock")
# Example1 - Calculating the cumulative moving average for data in
# the stockprice column.
movingaverage_cmavg = MovingAverage(data=ibm_stock,
data_order_column='name',
data_partition_column='name',
target_columns='stockprice',
mavgtype='C'
)
# Print the results.
print(movingaverage_cmavg.result)
# Example2 - Calculating the exponential moving average for data in
# the stockprice column.
movingaverage_emavg = MovingAverage(data=ibm_stock,
data_partition_column='name',
data_order_column='name',
target_columns='stockprice',
include_first=False,
alpha=0.1,
start_rows=10,
mavgtype='E'
)
# Print the results.
print(movingaverage_emavg.result)
# Example3 - Calculating the simple moving average for data in
# the stockprice column.
movingaverage_smavg = MovingAverage(data=ibm_stock,
data_partition_column='name',
data_order_column='name',
target_columns='stockprice',
include_first=False,
window_size=6,
mavgtype='S'
)
# Print the results.
print(movingaverage_smavg.result)
- __repr__(self)
- Returns the string representation for a MovingAverage class instance.
|