Teradata Package for Python Function Reference | 17.10 - SVMSparsePredict - 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.10
Published
April 2022
Language
English (United States)
Last Update
2022-08-19
lifecycle
previous
Product Category
Teradata Vantage
 
 
SVMSparsePredict

 
Functions
       
SVMSparsePredict(object=None, newdata=None, sample_id_column=None, attribute_column=None, value_column=None, accumulate_label=None, output_class_num=1, output_prob=True, output_responses=None, **generic_arguments)
DESCRIPTION:
The SVMSparsePredict() function takes the model generated by the
SVMSparse() trainer function and a set of test samples (in sparse
format) and outputs a prediction for each sample.
 
 
PARAMETERS:
    object:
        Required Argument.
        Specifies the teradataml DataFrame containing the model data
        generated by SVMSparse() function or instance of SVMSparse.
        Types: teradataml DataFrame or SVMSparse
 
    newdata:
        Required Argument.
        Specifies the teradataml DataFrame containing the input test data.
        Types: teradataml DataFrame
 
    sample_id_column:
        Required Argument.
        Specifies the name of the newdata column that contains the
        identifiers of the test samples. The newdata table must be
        partitioned by this column.
        Types: str
 
    attribute_column:
        Required Argument.
        Specifies the name of the newdata column that contains the
        attributes of the test samples.
        Types: str
 
    value_column:
        Optional Argument.
        Specifies the name of the newdata column that contains the
        attribute values. By default, each attribute has the value 1.
        Types: str
 
    accumulate_label:
        Optional Argument.
        Specifies the names of the newdata columns to copy to the
        output teradataml DataFrame.
        Types: str OR list of Strings (str)
 
    output_class_num:
        Optional Argument.
        Specifies the number of class labels to appear in the output
        teradataml DataFrame, with its corresponding prediction confidence.
        Valid only for multiple-class models.
        Default Value: 1
        Types: int
 
    output_prob:
        Optional Argument.
        Specifies whether to display output probability for the predicted
        category.
        Default Value: True
        Types: bool
 
    output_responses:
        Optional Argument.
        Specifies responses for which to output probabilities.
        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 table or not.
                When set to True, results are persisted in table; otherwise, results
                are garbage collected at the end of the session.
                Default Value: False
                Types: boolean
 
            volatile:
                Optional Argument.
                Specifies whether to put the results of the function in volatile table or not.
                When set to True, results are stored in volatile table, otherwise not.
                Default Value: False
                Types: boolean
 
        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 SQLE Engine
            function supports, else an exception is raised.
 
 
RETURNS:
    Instance of SVMSparsePredict.
    Output teradataml DataFrames can be accessed using attribute
    references, such as SVMSparsePredictObj.<attribute_name>.
    Output teradataml DataFrame attribute name is:
        result
 
 
RAISES:
    TeradataMlException, TypeError, ValueError
 
 
EXAMPLES:
    # Notes:
    #    1. Get the connection to Vantage, before importing the function in user space.
    #    2. User can import the function, if it is available on the Vantage user is connected to.
    #    3. To check the list of analytic functions available on the Vantage user connected to,
    #       use "display_analytic_functions()".
 
    # Load the data to run the example.
    load_example_data("SVMSparsePredict",["svm_iris_input_train","svm_iris_input_test"])
 
    # Create teradataml DataFrame
    svm_iris_input_train = DataFrame.from_table("svm_iris_input_train")
    svm_iris_input_test = DataFrame.from_table("svm_iris_input_test")
 
    # Create SparseSVMTrainer object
    svm_train = SVMSparse(data=svm_iris_input_train,
                        sample_id_column='id',
                        attribute_column='attribute',
                        label_column='species',
                        value_column='value1',
                        max_step=150,
                        seed=0)
 
    # Check the list of available analytic functions.
    display_analytic_functions()
 
    # Import function SVMSparsePredict.
    from teradataml import SVMSparsePredict
 
    # Example 1: Instance of SVMTrainer is passed as input to object argument.
    svm_sparse_predict_result1 = teradataml.SVMSparsePredict(newdata=svm_iris_input_test,
                                                             object=svm_train,
                                                             attribute_column='attribute',
                                                             sample_id_column='id',
                                                             value_column='value1',
                                                             accumulate_label='species')
 
    # Print the result DataFrame
    print(svm_sparse_predict_result1.result)
 
    # Example 2: teradataml DataFrame containing the model data generated by SVMSparse
    #            is passed as input to object argument.
    svm_sparse_predict_result2 = teradataml.SVMSparsePredict(newdata=svm_iris_input_test,
                                                             object=svm_train.model_table,
                                                             attribute_column='attribute',
                                                             sample_id_column='id',
                                                             value_column='value1',
                                                             accumulate_label='species')
 
    # Print the result DataFrame
    print(svm_sparse_predict_result2.result)
 
    # Example 3: Predict the species and display probability for "setosa" and "virginica".
    svm_sparse_predict_result3 = teradataml.SVMSparsePredict(newdata=svm_iris_input_test,
                                                             object=svm_train.model_table,
                                                             attribute_column='attribute',
                                                             sample_id_column='id',
                                                             value_column='value1',
                                                             accumulate_label='species',
                                                             output_prob= True,
                                                             output_responses= ['setosa', 'virginica'])
 
    # Print the result DataFrame.
    print(svm_sparse_predict_result3.result)