| |
Methods defined here:
- __init__(self, data=None, target_column_pairs=None, target_columns=None, partition_columns=None, exception_attribute=None, vif=False, vif_summary=None, vif_threshold=10.0, data_sequence_column=None)
- DESCRIPTION:
The Correlation2 function computes correlations between specified
pairs of teradataml DataFrame columns. Measuring correlation lets you
determine if the value of one variable is useful in predicting the
value of another. You can also use Correlation2 to detect and remove
collinearity in input data by computing variance inflation factor
(VIF).
Note:
1. This function is supported only on Vantage 1.3 or later.
2. Teradata recommends to use Correlation2 on Vantage 1.3 instead of Correlation.
PARAMETERS:
data:
Required Argument.
Specifies the input teradataml DataFrame that contains the Xi and Yi pairs.
target_column_pairs:
Required when the argument "vif" is set to 'False', disallowed otherwise.
Specifies pairs of columns for which correlations are to be calculated.
For each column pair, "col_name1:col_name2", the function calculates
the correlation between col_name1 and col_name2.
For each column range, "[col_index1:col_index2]", the function calculates
the correlation between every pair of columns in the range.
For example, if you specify "[1:3]", the function calculates the correlation
between the pairs (1,2), (1,3), (2,3),(1,1),(3,3). The mininum value of
col_index1 is 0 and col_index1 must be less than col_index2.
Types: str OR list of Strings (str)
target_columns:
Required when the argument "vif" is set to 'True', disallowed otherwise.
Specifies the names of the target columns for which to compare the VIF
with the specified vif_threshold.
Types: str OR list of Strings (str)
partition_columns:
Optional Argument.
Specifies the names of the input columns that define the group for
calculating correlation. By default, all input columns belong to a
single group, for which the function is calculating correlation.
Types: str OR list of Strings (str)
exception_attribute:
Optional when argument "vif" is set to 'True', disallowed otherwise.
Specifies the name of the column that will not be eliminated even if
VIF score is larger than the value in "vif_threshold" argument.
Types: str
Note:
Values in "exception_attribute" must also be specified in the
argument "target_columns".
vif:
Optional Argument.
Specifies whether the function computes the VIF score or not.
Default Value: False
Types: bool
vif_threshold:
Optional when the argument "vif" is set to 'True', disallowed otherwise.
Specifies the threshold for calculated VIF score.
If the VIF score for a predictor is above this threshold,
we can eliminate it in the modeling process.
To detect significant collinearity, specify a vif_threshold in [5.0, 20.0].
Default Value: 10.0
Types: float
vif_summary:
Optional when the argument "vif" is set to 'True', disallowed otherwise.
Specifies whether to output the final VIF scores or VIF scores from
each iteration of the algorithm.
When set to 'True', final VIF score is displayed.
When set to 'False', VIF score at the end of each iteration is displayed.
Default Value: True
Types: bool
data_sequence_column:
Optional Argument.
Specifies the list of column(s) that uniquely identifies each row of
the input argument "data". The argument is used to ensure
deterministic results for functions which produce results that vary
from run to run.
Types: str OR list of Strings (str)
RETURNS:
Instance of Correlation2.
Output teradataml DataFrames can be accessed using attribute
references, such as Correlation2Obj.<attribute_name>.
Output teradataml DataFrame attribute names are:
1. correlation_data
2. output
RAISES:
TeradataMlException
EXAMPLES:
# Load example data.
load_example_data("correlation", "corr_input")
# Create teradataml DataFrame objects.
corr_input = DataFrame.from_table("corr_input")
# Example 1: The function calculates the correlation between each pair of columns
# in the "target_column_pairs" argument. This example compares GDP to GDPdeflator,
# the employed population to GDP, the number of people unemployed, and the number
# of people in the armed forces.
Correlation_out1 = Correlation2(data = corr_input,
target_column_pairs = ["[2:3]", "employed:gdp",
"employed:unemployed", "employed:armedforces"],
partition_columns = ["state"]
)
# Print the correlation_data DataFrame.
print(Correlation_out1.correlation_data)
# Example 2: This example does not use "vif" and omits the "partition_columns"
# argument, so the function determines the correlation values for the overall
# population and does not group the data by state.
Correlation_out2 = Correlation2(data = corr_input,
target_column_pairs = ["[2:3]", "employed:gdp",
"employed:unemployed", "employed:armedforces"]
)
# Print the correlation_data DataFrame.
print(Correlation_out2.correlation_data)
# Example 3: This example sets "vif" argument to 'True' but does not specify
# the "exception_attribute" argument.
Correlation_out3 = Correlation2(data = corr_input,
target_columns = ["gdp", "unemployed", "armedforces", "employed"],
partition_columns = ["state"],
vif = True,
vif_threshold = 10.0
)
# Print the correlation_data DataFrame.
print(Correlation_out3.correlation_data)
# Example 4: This example uses "vif" argument and specifies the
# "exception_attribute" argument.
Correlation_out4 = Correlation2(data = corr_input,
target_columns = ["gdp", "unemployed", "armedforces", "employed"],
partition_columns = ["state"],
exception_attribute = "gdp",
vif = True,
vif_threshold = 10.0
)
# Print the correlation_data DataFrame.
print(Correlation_out4.correlation_data)
# Example 5: This example sets "vif" argument to 'True', specifies the
# "exception_attribute" argument and sets "vif_summary" argument to 'False'
# to display only final VIF scores.
Correlation_out5 = Correlation2(data = corr_input,
target_columns = ["gdp", "unemployed", "armedforces", "employed"],
partition_columns = ["state"],
exception_attribute = "gdp",
vif = True,
vif_summary = False,
vif_threshold = 10.0
)
# Print the correlation_data DataFrame.
print(Correlation_out5.correlation_data)
# Example 6: This example uses "target_columns" and "partition_columns"
# as column ranges to display only final VIF scores.
Correlation_out6 = Correlation2(data = corr_input,
target_columns = ["gdp:employed"],
partition_columns = ["state:armedforces"],
exception_attribute = "gdp",
vif = True,
vif_summary = False,
vif_threshold = 10.0
)
# Print the correlation_data DataFrame.
print(Correlation_out6.correlation_data)
- __repr__(self)
- Returns the string representation for a Correlation2 class instance.
- get_build_time(self)
- Function to return the build time of the algorithm in seconds.
When model object is created using retrieve_model(), then the value returned is
as saved in the Model Catalog.
- get_prediction_type(self)
- Function to return the Prediction type of the algorithm.
When model object is created using retrieve_model(), then the value returned is
as saved in the Model Catalog.
- get_target_column(self)
- Function to return the Target Column of the algorithm.
When model object is created using retrieve_model(), then the value returned is
as saved in the Model Catalog.
- show_query(self)
- Function to return the underlying SQL query.
When model object is created using retrieve_model(), then None is returned.
|