| |
Methods defined here:
- __init__(self, formula=None, data=None, alpha=0.0, lambda1=0.0, max_iter_num=10000, stop_threshold=1e-07, family='Gaussian', randomization=False, data_sequence_column=None)
- DESCRIPTION:
The GLML1L2 function differs from the GLM function in these ways:
1. GLML1L2 supports the regularization models Ridge, LASSO, and
Elastic Net.
2. GLML1L2 outputs a model teradataml DataFrame and optionally,
a factor teradataml DataFrame (GLM outputs only a model).
PARAMETERS:
formula:
Required Argument.
A string consisting of "formula". Specifies the model to be fitted.
Only basic formula of the "col1 ~ col2 + col3 +..." form are
supported and all variables must be from the same teradataml
DataFrame object. The response should be column of type float, int or
bool.
data:
Required Argument.
Specifies the name of the teradataml DataFrame that contains the
input data.
alpha:
Optional Argument.
Specifies whether to use Lasso, Ridge or Elastic Net. If the value is
0, Ridge is used. If the value is 1, Lasso is used. For any value
between 0 and 1, Elastic Net is applied.
Default Value: 0.0
Types: float
lambda1:
Optional Argument.
Specifies the parameter that controls the magnitude of the regularization
term. The value lambda must be in the range [0.0, 100.0].
A value of zero disables regularization.
Default Value: 0.0
Types: float
max_iter_num:
Optional Argument.
Specifies the maximum number of iterations over the data.
The parameter max_iterations must be a positive int value in
the range [1, 100000].
Default Value: 10000
Types: int
stop_threshold:
Optional Argument.
Specifies the convergence threshold.
Default Value: 1.0E-7
Types: float
family:
Optional Argument.
Specifies the distribution exponential family.
Default Value: "Gaussian"
Permitted Values: Binomial, Gaussian
Types: str
randomization:
Optional Argument.
Specify whether to randomize the input teradataml DataFrame data.
Default Value: False
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 GLML1L2.
Output teradataml DataFrames can be accessed using attribute
references, such as GLML1L2Obj.<attribute_name>.
Output teradataml DataFrame attribute names are:
1. output
2. factor_data
Note:
1. When argument randomization is True or if any categorical columns
are provided in formula argument, then and only then output teradataml DataFrame
factor_data is created.
2. factor_data can be used as the input (data) for future GLML1L2
function calls, thereby saving the function from repeating the
categorical-to-numerical conversion or randomization.
RAISES:
TeradataMlException
EXAMPLES:
# Load the data to run the example.
load_example_data("GLML1L2", ["admissions_train", "housing_train"])
# Create teradataml DataFrame object.
admissions_train = DataFrame.from_table("admissions_train")
housing_train = DataFrame.from_table("housing_train")
# Example 1 - The input DataFrame is admission_train, running GLML1L2 function as
# Ridge Regression Analysis. Alpha (0.0) indicates L2 (ridge regression).
glml1l2_out1 = GLML1L2(data=admissions_train,
formula = "admitted ~ masters + gpa + stats + programming",
alpha=0.0,
lambda1=0.02,
family='Binomial',
randomization=True
)
# Print the output DataFrames.
# STDOUT DataFrame.
print(glml1l2_out1.output)
# factor_data dataframe.
print(glml1l2_out1.factor_data)
# Example 2 - The input DataFrame is factor_data DataFrame which is generated by
# (GLML1L2 Example 1: Ridge Regression, Binomial Family). In factor_data DataFrame
# categorical predictors were converted to integers.
glml1l2_out2 = GLML1L2(data=glml1l2_out1.factor_data,
formula = "admitted ~ masters_yes + stats_beginner + stats_novice + programming_beginner + programming_novice + gpa",
alpha=0.0,
lambda1=0.02,
family='Binomial'
)
# Print the result.
print(glml1l2_out2)
# Example 3 - The input DataFrame is housing_train, running GLML1L2 function as
# LASSO Regression (Family Gaussian distribution). Alpha (1.0) indicates
# L1 (LASSO) regularization.
glml1l2_out3 = GLML1L2(data=housing_train ,
formula = "price ~ lotsize + bedrooms + bathrms + stories + garagepl + driveway + recroom + fullbase + gashw + airco + prefarea + homestyle",
alpha=1.0,
lambda1=0.02,
family='Gaussian'
)
# Print all output dataframes.
print(glml1l2_out3.output)
print(glml1l2_out3.factor_data)
- __repr__(self)
- Returns the string representation for a GLML1L2 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.
|