NBTrainer: Naive Bayes Trainer

Description Details Public fields Methods Examples

Description

Trains a probabilistic naive bayes model

Details

Trains a naive bayes model. It is built on top high performance naivebayes R package.

Public fields

prior

numeric vector with prior probabilities. vector with prior probabilities of the classes. If unspecified, the class proportions for the training set are used. If present, the probabilities should be specified in the order of the factor levels.

laplace

value used for Laplace smoothing. Defaults to 0 (no Laplace smoothing)

usekernel

if TRUE, density is used to estimate the densities of metric predictors

model

for internal use

Methods

Public methods


Method new()

Usage
NBTrainer$new(prior, laplace, usekernel)
Arguments
prior

numeric, prior numeric vector with prior probabilities. vector with prior probabilities of the classes. If unspecified, the class proportions for the training set are used. If present, the probabilities should be specified in the order of the factor levels.

laplace

nuemric, value used for Laplace smoothing. Defaults to 0 (no Laplace smoothing)

usekernel

logical, if TRUE, density is used to estimate the densities of metric predictors

Details

Create a new 'NBTrainer' object.

Returns

A 'NBTrainer' object.

Examples
data(iris)
nb <- NBTrainer$new()

Method fit()

Usage
NBTrainer$fit(X, y)
Arguments
X

data.frame containing train features

y

character, name of target variable

Details

Fits the naive bayes model

Returns

NULL, trains and saves the model in memory

Examples
data(iris)
nb <- NBTrainer$new()
nb$fit(iris, 'Species')

Method predict()

Usage
NBTrainer$predict(X, type = "class")
Arguments
X

data.frame containing test features

type

character, if the predictions should be labels or probability

Details

Returns predictions from the model

Returns

NULL, trains and saves the model in memory

Examples
data(iris)
nb <- NBTrainer$new()
nb$fit(iris, 'Species')
y <- nb$predict(iris)

Method clone()

The objects of this class are cloneable with this method.

Usage
NBTrainer$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## ------------------------------------------------
## Method `NBTrainer$new`
## ------------------------------------------------

data(iris)
nb <- NBTrainer$new()

## ------------------------------------------------
## Method `NBTrainer$fit`
## ------------------------------------------------

data(iris)
nb <- NBTrainer$new()
nb$fit(iris, 'Species')

## ------------------------------------------------
## Method `NBTrainer$predict`
## ------------------------------------------------

data(iris)
nb <- NBTrainer$new()
nb$fit(iris, 'Species')
y <- nb$predict(iris)

superml documentation built on April 28, 2020, 9:05 a.m.