| |
- TDNaiveBayesPredict(data=None, object=None, id_column=None, numeric_inputs=None, categorical_inputs=None, attribute_name_column=None, attribute_value_column=None, responses=None, output_prob=False, accumulate=None, **generic_arguments)
- DESCRIPTION:
Function predicts classification label using model generated by NaiveBayes function
for a test set of data.
PARAMETERS:
data:
Required Argument.
Specifies the input teradataml DataFrame.
Types: teradataml DataFrame
object:
Required Argument.
Specifies the teradataml DataFrame containing the model data
or instance of NaiveBayes.
Types: teradataml DataFrame or NaiveBayes
id_column:
Required Argument.
Specifies the name of the column that uniquely identifies an
observation in the "data".
Types: str
numeric_inputs:
Optional Argument.
Specifies the name of the columns in "data" containing numeric attributes values.
Types: str OR list of Strings (str)
categorical_inputs:
Optional Argument.
Specifies the name of the columns in "data" containing categorical attributes values.
Types: str OR list of Strings (str)
attribute_name_column:
Optional Argument.
Specifies the name of the columns in "data" containing attributes names.
Types: str
attribute_value_column:
Optional Argument.
Specifies the name of the columns in "data" containing attributes values.
Types: str
responses:
Optional Argument.
Specifies a list of responses to output.
Types: str OR list of strs
output_prob:
Optional Argument.
Specifies whether to output the probability for each response.
Default Value: False
Types: bool
accumulate:
Optional Argument.
Specify the names of the columns in "data" that need to be copied
from the input to output teradataml DataFrame.
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 NaiveBayesPredict.
Output teradataml DataFrames can be accessed using attribute
references, such as NaiveBayesPredictObj.<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
# Vantage user is connected to.
# 3. To check the list of analytic functions available on
# Vantage user connected to, use
# "display_analytic_functions()".
# Load the example data.
load_example_data("decisionforestpredict", ["housing_train", "housing_test"])
# Create teradataml DataFrame objects.
housing_train = DataFrame.from_table("housing_train")
housing_test = DataFrame.from_table("housing_test")
# Check the list of available analytic functions.
display_analytic_functions()
# Import function TDNaiveBayesPredict.
from teradataml import TDNaiveBayesPredict, NaiveBayes, Unpivoting
# Example 1: TDNaiveBayesPredict function to predict the classification label using Dense input.
NaiveBayes_out = NaiveBayes(data=housing_train, response_column='homestyle',
numeric_inputs=['price','lotsize','bedrooms','bathrms','stories','garagepl'],
categorical_inputs=['driveway','recroom','fullbase','gashw','airco','prefarea'])
NaiveBayesPredict_out = TDNaiveBayesPredict(data=housing_test, object=NaiveBayes_out.result, id_column='sn',
numeric_inputs=['price','lotsize','bedrooms','bathrms','stories','garagepl'],
categorical_inputs=['driveway','recroom','fullbase','gashw','airco','prefarea'],
responses=['Classic', 'Eclectic', 'bungalow'],
accumulate='homestyle',
output_prob=True
)
# Print the result DataFrame.
print( NaiveBayesPredict_out.result)
# Example 2: TDNaiveBayesPredict function to predict the classification label using Sparse input.
# Unpivoting the data for sparse input to naive bayes.
upvt_train = Unpivoting(data = housing_train, id_column = 'sn',
target_columns = ['price','lotsize','bedrooms','bathrms','stories','garagepl',
'driveway','recroom','fullbase','gashw','airco','prefarea'],
attribute_column = "AttributeName",
value_column = "AttributeValue",
accumulate = 'homestyle')
upvt_test = Unpivoting(data = housing_test, id_column = 'sn',
target_columns = ['price','lotsize','bedrooms','bathrms','stories','garagepl','driveway',
'recroom','fullbase','gashw','airco','prefarea'],
attribute_column = "AttributeName", value_column = "AttributeValue",
accumulate = 'homestyle')
NaiveBayes_out1 = NaiveBayes(data=upvt_train.result,
response_column='homestyle',
attribute_name_column='AttributeName',
attribute_value_column='AttributeValue',
numeric_attributes=['price','lotsize','bedrooms','bathrms','stories','garagepl'],
categorical_attributes=['driveway','recroom','fullbase','gashw','airco','prefarea'])
NaiveBayesPredict_out1 = TDNaiveBayesPredict(data=upvt_test.result, object=NaiveBayes_out1, id_column='sn',
attribute_name_column='AttributeName',
attribute_value_column='AttributeValue',
responses=['Classic', 'Eclectic', 'bungalow'],
accumulate='homestyle',
output_prob=True
)
# Print the result DataFrame.
print( NaiveBayesPredict_out1.result)
|