Teradata Package for Python Function Reference | 17.10 - mlinreg - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.
Teradata® Package for Python Function Reference
- Product
- Teradata Package for Python
- Release Number
- 17.10
- Published
- April 2022
- Language
- English (United States)
- Last Update
- 2022-08-19
- lifecycle
- previous
- Product Category
- Teradata Vantage
- teradataml.dataframe.sql.DataFrameColumn.mlinreg = mlinreg(width, sort_column)
- DESCRIPTION:
Computes the moving linear regression for the current row and the preceding
"width"-1 rows in a partition, by sorting the rows according to "sort_column".
Note:
mlinreg does not support below type of columns.
* BLOB
* BYTE
* CHAR
* CLOB
* DATE
* PERIOD_DATE
* PERIOD_TIME
* PERIOD_TIMESTAMP
* TIME
* TIMESTAMP
* VARBYTE
* VARCHAR
PARAMETERS:
width:
Required Argument.
Specifies the width of the partition. "width" must be
greater than 0 and less than or equal to 4096.
Types: int
sort_column:
Required Argument.
Specifies the column to use for sorting.
Note:
"sort_column" does not support CLOB and BLOB type of
columns.
Types: str (or) ColumnExpression
RAISES:
TeradataMlException, TypeError
RETURNS:
ColumnExpression, also known as, teradataml DataFrameColumn.
NOTES:
* One must use DataFrame.assign() when using the aggregate functions on
ColumnExpression, also known as, teradataml DataFrameColumn.
* ColumnExpression specified in "sort_columns" should be from the same
teradataml DataFrame as that of the ColumnExpression invoking the function.
EXAMPLES:
# Load the data to run the example.
>>> from teradataml import load_example_data
>>> load_example_data("dataframe","admissions_train")
>>> df = DataFrame('admissions_train')
>>> print(df)
masters gpa stats programming admitted
id
15 yes 4.00 Advanced Advanced 1
7 yes 2.33 Novice Novice 1
22 yes 3.46 Novice Beginner 0
17 no 3.83 Advanced Advanced 1
13 no 4.00 Advanced Novice 1
38 yes 2.65 Advanced Beginner 1
26 yes 3.57 Advanced Advanced 1
5 no 3.44 Novice Novice 0
34 yes 3.85 Advanced Beginner 0
40 yes 3.95 Novice Beginner 0
>>>
# Example 1: Calculate the moving linear regression for column 'id' by
# sorting the data on column accounts in descending order, with window of size 3.
>>> df.assign(mlinreg_id=df.id.mlinreg(3, df.id))
masters gpa stats programming admitted mlinreg_id
id
3 no 3.70 Novice Beginner 1 3.0
5 no 3.44 Novice Novice 0 5.0
6 yes 3.50 Beginner Advanced 1 6.0
7 yes 2.33 Novice Novice 1 7.0
9 no 3.82 Advanced Advanced 1 9.0
10 no 3.71 Advanced Advanced 1 10.0
8 no 3.60 Beginner Advanced 1 8.0
4 yes 3.50 Beginner Novice 1 4.0
2 yes 3.76 Beginner Beginner 0 NaN
1 yes 3.95 Beginner Beginner 0 NaN
>>>