PREDICT_NAIVE_BAYES

Applies a Naive Bayes model on an input table or view.

Important: Before using a machine learning function, be aware that all the ongoing transactions might be committed.

Syntax

PREDICT_NAIVE_BAYES ( predictor_columns
                        USING PARAMETERS model_name = 'model_name'
                                         [, type = ' { RESPONSE | PROBABILITY } ',]
                                         [class = 'user_input_class', ] 
                                         [match_by_pos = 'method'] )

Arguments

predictor_columns

A comma-separated list of the columns in input_relation that represent the independent features for the model.

Supports the use of wildcard (*) characters in place of column names.

Parameters

model_name = 'model_name'

The name of the model. Model names are case insensitive.

type = '{ RESPONSE | PROBABILITY }'

(Optional) Specifies that the function can take the value RESPONSE or PROBABILITY. RESPONSE, using the class result of the prediction. This value uses the highest probability among all possible classes. PROBABILITY defers to the second argument 'class'.

Default Value: response

class = 'user_input_class'

(Optional) Specifies a specific class to use when type is set to PROBABILITY. The predict function returns the probability of belonging to this given class as predicted by the classifier. If class is not specified, its default value is the predicted class -- the highest will be returned. Thus, the predict function returns the probability that the input instance belonging to its predicted class.

match_by_pos= 'method'

(Optional) Valid Values:

  • false (default): Input columns will be matched to features in the model based on their names.

  • true: Input columns will be matched to features in the model based on their position in the list of indicated input columns.

Return

Return data type: VARCHAR

Returns the predicted class or the probability of the predicted class, depending on the response input. The return can be cast to INT or other numeric types when the return is in the probability of the predicted class.

Examples

This example shows how you can use the PREDICT_NAIVE_BAYES function.

=> SELECT party, PREDICT_NAIVE_BAYES (vote1, vote2, vote3
                                        USING PARAMETERS model_name = 'naive_house84_model',
                                                         type = 'response') 
                                        AS Predicted_Party
                                        FROM house84_test;
   party    | Predicted_Party
------------+-----------------
 democrat   | democrat
 democrat   | democrat
 democrat   | democrat
 republican | republican
 democrat   | democrat
 democrat   | democrat
 democrat   | democrat
 democrat   | democrat
 democrat   | democrat
 republican | republican
 democrat   | democrat
 democrat   | democrat
 democrat   | democrat
 democrat   | republican
 republican | republican
 democrat   | democrat
 republican | republican
.
.
.
(99 rows)

See Also