Loading...

vastorbit.VastFrame.polynomial_comb

VastFrame.polynomial_comb(columns: Annotated[str | list[str], 'STRING representing one column or a list of columns'] | None = None, r: int = 2) VastFrame

Returns a VastFrame containing the different product combinations of the input VastColumn. This function is ideal for bivariate analysis.

Parameters:
  • columns (SQLColumns, optional) – List of the VastColumn names. If empty, all numerical VastColumn are used.

  • r (int, optional) – Degree of the polynomial.

Returns:

the Polynomial object.

Return type:

VastFrame

Examples

Let’s begin by importing vastorbit.

import vastorbit as vo

Hint

By assigning an alias to vastorbit, we mitigate the risk of code collisions with other libraries. This precaution is necessary because vastorbit uses commonly known function names like “average” and “median”, which can potentially lead to naming conflicts. The use of an alias ensures that the functions from vastorbit are used as intended without interfering with functions from other libraries.

Let us create a VastFrame with multiple columns:

vdf = vo.VastFrame(
    {
        "col1": [1, 2, 3],
        "col2": [0, 7, 8],
        "col3": [3, 11, 93],
    }
)
123
col1
Integer
123
col2
Integer
123
col3
Integer
12711
2103
33893
Rows: 1-3 | Columns: 3

We can create a new VastFrame that has a combination of the original columns using the VastFrame.polynomial_comb() method:

new_vdf = vdf.polynomial_comb(r = 2)
123
col1
Integer
123
col2
Integer
123
col3
Integer
123
col1_col1
Integer
123
col1_col2
Integer
123
col1_col3
Integer
123
col2_col2
Integer
123
col2_col3
Integer
123
col3_col3
Integer
13893924279647448649
22711414224977121
3103103009
Rows: 1-3 | Columns: 9

Note

This function is highly useful for data preparation, as certain combinations of variables may be relevant for predicting a specific column. It can be beneficial to combine it with a correlation matrix to determine if any of the created combinations can influence the response column.

See also

VastFrame.corr() : Computes the correlation matrix.