| |
Methods defined here:
- __init__(self, formula=None, family='gaussian', linkfunction='CANONICAL', data=None, weights='1.0', threshold=0.01, maxit=25, step=False, intercept=True, data_sequence_column=None)
- DESCRIPTION:
The generalized linear model (GLM) is an extension of the linear
regression model that enables the linear equation to be related to
the dependent variables by a link function. GLM performs linear
regression analysis for distribution functions using a user-specified
distribution family and link function. GLM selects the link function
based upon the distribution family and the assumed nonlinear
distribution of expected outcomes. The teradataml DataFrame in
Background describes the supported link function combinations.
PARAMETERS:
formula:
Required Argument.
A string consisting of "formula". Specifies the model to be fitted. Only
basic formula of the "col1 ~ col2 + col3 +..." form is supported and
all variables must be from the same virtual data frame object. The
response should be column of type real, numeric, integer or boolean.
Types: str
family:
Optional Argument.
Specifies the distribution exponential family
Default Value: "gaussian"
Permitted Values: LOGISTIC, BINOMIAL, POISSON, GAUSSIAN, GAMMA,
INVERSE_GAUSSIAN, NEGATIVE_BINOMIAL
Types: str
linkfunction:
Optional Argument.
The canonical link functions (default link functions) and the link
functions that are allowed.
Default Value: "CANONICAL"
Permitted Values: CANONICAL, IDENTITY, INVERSE, LOG,
COMPLEMENTARY_LOG_LOG, SQUARE_ROOT, INVERSE_MU_SQUARED, LOGIT,
PROBIT, CAUCHIT
Types: str
data:
Required Argument.
Specifies the name of the teradataml DataFrame that contains the
columns.
weights:
Optional Argument.
Specifies the name of an input teradataml DataFrame column that
contains the weights to assign to responses. The default value is
1.You can use non-NULL weights to indicate that different
observations have different dispersions (with the weights being
inversely proportional to the dispersions).Equivalently, when the
weights are positive integers wi, each response yi is the mean of wi
unit-weight observations. A binomial GLM uses prior weights to give
the number of trials when the response is the proportion of
successes. A Poisson GLM rarely uses weights. If the weight is less
than the response value, then the function throws an exception.
Therefore, if the response value is greater than 1 (the default
weight), then you must specify a weight that is greater than or equal
to the response value.
Default Value: "1.0"
Types: str
threshold:
Optional Argument.
Specifies the convergence threshold.
Default Value: 0.01
Types: float
maxit:
Optional Argument.
Specifies the maximum number of iterations that the algorithm runs
before quitting if the convergence threshold has not been met.
Default Value: 25
Types: int
step:
Optional Argument.
Specifies whether the function uses a step. If the function uses a
step, then it runs with the GLM model that has the lowest Akaike
information criterion (AIC) score, drops one predictor from the
current predictor group, and repeats this process until no predictor
remains.
Default Value: False
Types: bool
intercept:
Optional Argument.
Specifies whether the function uses an intercept. For example, in
ß0+ß1*X1+ß2*X2+ ....+ßpXp, the intercept is ß0.
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 GLM.
Output teradataml DataFrames can be accessed using attribute
references, such as GLMObj.<attribute_name>.
Output teradataml DataFrame attribute name is:
1. coefficients
2. output
RAISES:
TeradataMlException
EXAMPLES:
# Load the data to run the example.
load_example_data("GLM", ["admissions_train", "housing_train"])
# Create teradataml DataFrame objects.
admissions_train = DataFrame.from_table("admissions_train")
housing_train = DataFrame.from_table("housing_train")
# Example 1 -
glm_out1 = GLM(formula = "admitted ~ stats + masters + gpa + programming",
family = "LOGISTIC",
linkfunction = "LOGIT",
data = admissions_train,
weights = "1",
threshold = 0.01,
maxit = 25,
step = False,
intercept = True
)
# Print the output dataframes
# STDOUT DataFrame
print(glm_out1.output)
# GLM Model, coefficients DataFrame
print(glm_out1.coefficients)
# Example 2 -
glm_out2 = GLM(formula = "admitted ~ stats + masters + gpa + programming",
family = "LOGISTIC",
linkfunction = "LOGIT",
data = admissions_train,
weights = "1",
threshold = 0.01,
maxit = 25,
step = True,
intercept = True
)
# Print all output dataframes
print(glm_out2.output)
# Example 3 -
glm_out3 = GLM(formula = "price ~ recroom + lotsize + stories + garagepl + gashw + bedrooms + driveway + airco + homestyle + bathrms + fullbase + prefarea",
family = "GAUSSIAN",
linkfunction = "IDENTITY",
data = housing_train,
weights = "1",
threshold = 0.01,
maxit = 25,
step = False,
intercept = True
)
# Print all output dataframes
print(glm_out3.output)
print(glm_out1.coefficients)
- __repr__(self)
- Returns the string representation for a GLM 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.
|