Teradata Package for Python Function Reference - LinRegPredict - 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.00
Published
November 2021
Language
English (United States)
Last Update
2021-11-19
lifecycle
previous
Product Category
Teradata Vantage
 
 
LinRegPredict

 
Functions
       
LinRegPredict(data, model, index_columns=None, response_column=None, accumulate=None)
DESCRIPTION:
    Linear Regression Scoring is the application of a Linear Regression model to an input
    data that contains the same independent variable columns contained in the model. The
    result is an output score data that minimally contains one or more key columns and
    an estimate of the dependent variable in the model.
 
    Some of the key features of linear scoring are outlined below.
        * If one or more group by columns are present in the input data to be scored and
          the model input data, each row in the input data to be scored is scored using
          the appropriate model in the model input data.
        * If an error such as "Constant columns detected" occurs for a particular
          combination of group by column values, the predicted value of the dependent
          column is null for any row containing that combination of group by column
          values. The error message is also placed in the column name in the model report.
    
PARAMETERS:
    data:
        Required Argument.
        Specifies the input data to score.
        Types: teradataml DataFrame
    
    model:
        Required Argument.
        Specifies the input containing the linear model to use in scoring. This must be
        the "model" teradataml DataFrame generated by LinReg() function from VALIB or a
        teradataml DataFrame created on a table generated by 'linear' function from
        Vantage Analytic Library.
        Types: teradataml DataFrame
    
    index_columns:
        Optional Argument.
        Specifies the name(s) of the column(s) representing the primary index of the
        score output. By default, the primary index columns of the score output are the
        primary index columns of the input. In addition, the index columns need to form
        a unique key for the score output. Otherwise, there are more than one score for
        a given observation.
        Types: str OR list of Strings (str)
    
    response_column:
        Optional Argument.
        Specifies the name of the predicted value column. If not used, the name of the
        dependent column in the input is used.
        Types: str
    
    accumulate:
        Optional Argument.
        Specifies the name(s) of the column(s) from the input to retain in the output.
        Types: str OR list of Strings (str)
    
RETURNS:
    An instance of LinRegPredict.
    Output teradataml DataFrames can be accessed using attribute references, such as 
    LinRegPredictObj.<attribute_name>.
    Output teradataml DataFrame attribute name is: result
    
RAISES:
    TeradataMlException, TypeError, ValueError
    
EXAMPLES:
    # Notes:
    #   1. To execute Vantage Analytic Library functions,
    #       a. import "valib" object from teradataml.
    #       b. set 'configure.val_install_location' to the database name where Vantage 
    #          analytic library functions are installed.
    #   2. Datasets used in these examples can be loaded using Vantage Analytic Library 
    #      installer.
    # Import valib object from teradataml to execute this function.
    from teradataml import valib
 
    # Set the 'configure.val_install_location' variable.
    from teradataml import configure
    configure.val_install_location = "SYSLIB"
 
    # Create required teradataml DataFrame.
    df = DataFrame("customer")
    print(df)
    
    # Example 1: Shows how linear regression model scoring is performed.
    # First generate the model using LinReg() function from 'valib'.
    lin_reg_obj = valib.LinReg(data=df,
                               columns=["age", "years_with_bank", "nbr_children"],
                               response_column="income")
 
    # Print the linear regression model.
    print(lin_reg_obj.model)
    
    # Score the data using the linear regression model generated above.
    obj = valib.LinRegPredict(data=df,
                              model=lin_reg_obj.model,
                              response_column="inc")
 
    # Print the results.
    print(obj.result)