Learn R Programming

ibmdbR (version 1.42.2)

idaNaiveBayes: Naive Bayes Classifier

Description

This function generates a Naive Bayes classification model based on the contents of a IDA data frame (ida.data.frame).

Usage

idaNaiveBayes(form,data,id="id",modelname=NULL)

## S3 method for class 'idaNaiveBayes':
predict(object,newdata,id,...)
## S3 method for class 'idaNaiveBayes':
print(x,...)

Arguments

form
A formula object that describes the model to fit.
data
A ida.data.frame object.
id
The name of the column that contains unique IDs.
modelname
Name for the model. Will be created automatically unless specified otherwise.
object
An object of the class idaNaiveBayes to be predicted.
newdata
A IDA data frame that contains the data to which to apply the model.
x
An object of the class idaNaiveBayes to be printed.
...
Additional parameters to pass to the print and predict method.

Value

  • The function idaNaiveBayes returns an object of class "idaNaiveBayes" and "naiveBayes" compatible with Naive Bayes objects produced by the e1071 package. The predict.idaNaiveBayes method applies the model to the data in a table and returns a IDA data frame that contains a list of tuples, each of which comprises one row ID and one prediction.

Details

idaNaiveBayes builds a Naive Bayes classification model, thus a model that assumes independence of input variables with respect to the target variable. Continuous input variables are discretized using equal width discretization. Missing values are ignored on a record and attribute level when calculating the conditional probabilities. Models are stored persistently in database under the name modelname. Model names cannot have more than 64 characters and cannot contain white spaces. They need to be quoted like table names, otherwise they will be treated upper case by default. Only one model with a given name is allowed in the database at a time. If a model with modelname already exists, you need to drop it with idaDropModel first before you can create another one with the same name. The model name can be used to retrieve the model later (idaRetrieveModel).

Examples

Run this code
#Create ida data frame
idf <- ida.data.frame("IRIS")

#Create a naive bayes model
nb <- idaNaiveBayes(Species~SepalLength,idf,"ID")

#Print the model
print(nb)

#Apply the model to data
idf2 <- predict(nb,idf,"ID")

#Inspect the results
head(idf2)

Run the code above in your browser using DataLab