Teradata Package for Python Function Reference | 20.00 - OneClassSVMPredict - 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 - 20.00

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for Python
Release Number
20.00.00.03
Published
December 2024
ft:locale
en-US
ft:lastEdition
2024-12-19
dita:id
TeradataPython_FxRef_Enterprise_2000
Product Category
Teradata Vantage
 
 
OneClassSVMPredict

 
Functions
       
OneClassSVMPredict(object=None, newdata=None, id_column=None, accumulate=None, output_prob=False, output_responses=None, **generic_arguments)
DESCRIPTION:
    The OneClassSVMPredict() function uses the model generated
    by the function OneClassSVM() to predicts target class labels
    (classification) on new input data. Output values are 0 and 1.
    A value of 1 corresponds to a 'normal' observation, and a value
    of 0 is assigned to 'outlier' observations.
 
    Notes:
        * Standardize input features using ScaleFit() and ScaleTransform()
          before using the function.
        * The function takes only numeric features.
        * The categorical features must be converted to numeric values prior to prediction.
        * Rows with missing (null) values are skipped by the function during prediction.
        * For prediction results evaluation, user can use ClassificationEvaluator() or
          ROC() as the postprocessing step.
 
 
PARAMETERS:
    object:
        Required Argument.
        Specifies the teradataml DataFrame containing the model data
        generated by OneClassSVM() function or an instance of OneClassSVM.
        Types: teradataml DataFrame or OneClassSVM
 
    newdata:
        Required Argument.
        Specifies the teradataml DataFrame containing the input data.
        Types: teradataml DataFrame
 
    id_column:
        Required Argument.
        Specifies the name of the column that uniquely identifies an
        observation in the test data.
        Types: str
 
    accumulate:
        Optional Argument.
        Specifies the name(s) of input teradataml DataFrame column(s) to copy to the
        output.
        Types: str OR list of Strings (str)
 
    output_prob:
        Optional Argument.
        Specifies whether the function should output the probability for each
        response.
        Note:
            * Only applicable if "model_type" is 'Classification'.
        Default Value: False
        Types: bool
 
    output_responses:
        Optional Argument.
        Specifies the class labels for which to output probabilities.
        A label must be 0 or 1. If not specified, the function outputs the
        probability of the predicted response.
        Note:
            * Only applicable if "output_prob" is 'True'.
        Types: str OR list of Strings (str)
 
    **generic_arguments:
        Specifies the generic keyword arguments SQLE functions accept. Below
        are the generic keyword arguments:
            persist:
                Optional Argument.
                Specifies whether to persist the results of the
                function in a table or not. When set to True,
                results are persisted in a table; otherwise,
                results are garbage collected at the end of the
                session.
                Default Value: False
                Types: bool
 
            volatile:
                Optional Argument.
                Specifies whether to put the results of the
                function in a volatile table or not. When set to
                True, results are stored in a volatile table,
                otherwise not.
                Default Value: False
                Types: bool
 
        Function allows the user to partition, hash, order or local
        order the input data. These generic arguments are available
        for each argument that accepts teradataml DataFrame as
        input and can be accessed as:
            * "<input_data_arg_name>_partition_column" accepts str or
              list of str (Strings)
            * "<input_data_arg_name>_hash_column" accepts str or list
              of str (Strings)
            * "<input_data_arg_name>_order_column" accepts str or list
              of str (Strings)
            * "local_order_<input_data_arg_name>" accepts boolean
        Note:
            These generic arguments are supported by teradataml if
            the underlying SQL Engine function supports, else an
            exception is raised.
 
RETURNS:
    Instance of OneClassSVMPredict.
    Output teradataml DataFrames can be accessed using attribute
    references, such as OneClassSVMPredictObj.<attribute_name>.
    Output teradataml DataFrame attribute name is:
        result
 
 
RAISES:
    TeradataMlException, TypeError, ValueError
 
 
EXAMPLES:
    # Notes:
    #     1. Get the connection to Vantage to execute the function.
    #     2. One must import the required functions mentioned in
    #        the example from teradataml.
    #     3. Function will raise error if not supported on the Vantage
    #        user is connected to.
 
    # Load the example data.
    load_example_data("teradataml", ["cal_housing_ex_raw"])
 
    # Create teradataml DataFrame objects.
    data_input = DataFrame.from_table("cal_housing_ex_raw")
 
    # Check the list of available analytic functions.
    display_analytic_functions()
 
    # Scale "target_columns" with respect to 'STD' value of the column.
    fit_obj = ScaleFit(data=data_input,
                       target_columns=['MedInc', 'HouseAge', 'AveRooms',
                                       'AveBedrms', 'Population', 'AveOccup',
                                       'Latitude', 'Longitude'],
                       scale_method="STD")
 
    # Transform the data.
    transform_obj = ScaleTransform(data=data_input,
                                   object=fit_obj.output,
                                   accumulate=["id", "MedHouseVal"])
 
    # Train the input data by OneClassSVM which helps model
    # to find anomalies in transformed data.
    one_class_svm=OneClassSVM(data=transform_obj.result,
                              input_columns=['MedInc', 'HouseAge', 'AveRooms',
                                             'AveBedrms', 'Population', 'AveOccup',
                                             'Latitude', 'Longitude'],
                              local_sgd_iterations=537,
                              batch_size=1,
                              learning_rate='constant',
                              initial_eta=0.01,
                              lambda1=0.1,
                              alpha=0.0,
                              momentum=0.0,
                              iter_max=1
                              )
 
 
 
    # Example 1 : Using trained data by OneClassSVM model, predict whether observation
    #             is outlier or normal in the form of '0' or '1' on "newdata".
    OneClassSVMPredict_out1 = OneClassSVMPredict(object = one_class_svm.result,
                                                 newdata = transform_obj.result,
                                                 id_column = "id"
                                                 )
 
    # Print the result DataFrame.
    print(OneClassSVMPredict_out1.result)
 
    # Example 2 : Using trained data by OneClassSVM model, predict whether observation
    #             is outlier or normal  in the form of '0' or '1' also provides probability
    #             of outcome of '0' and '1' on "newdata".
    OneClassSVMPredict_out2 = OneClassSVMPredict(object = one_class_svm,
                                                 newdata = transform_obj.result,
                                                 id_column = "id",
                                                 accumulate="MedInc",
                                                 output_prob=True,
                                                 output_responses=["0", "1"]
                                                 )
    # Print the result DataFrame.
    print(OneClassSVMPredict_out2.result)