naiveBayes               package:e1071               R Documentation

_N_a_i_v_e _B_a_y_e_s _C_l_a_s_s_i_f_i_e_r

_D_e_s_c_r_i_p_t_i_o_n:

     Computes the conditional a-posterior probabilities of a
     categorical class variable given independent predictor variables
     using the Bayes rule.

_U_s_a_g_e:

     ## S3 method for class 'formula':
     naiveBayes(formula, data, ..., subset, na.action = na.pass)
     ## Default S3 method:
     naiveBayes(x, y, ...)

_A_r_g_u_m_e_n_t_s:

       x: A numeric matrix, or a data frame of categorical and/or
          numeric variables.

       y: Class vector.

 formula: A formula of the form 'class ~ x1 + x2 + ...'. Interactions
          are not allowed.

    data: Either a data frame of predictors (caegorical and/or numeric)
          or a contingency table.

     ...: Currently not used.

  subset: For data given in a data frame, an index vector specifying
          the cases to be used in the training sample.  (NOTE: If
          given, this argument must be named.)

na.action: A function to specify the action to be taken if 'NA's are
          found. The default action is not to count them for the
          computation of the probability factors. An alternative is
          na.omit, which leads to rejection of cases with missing
          values on any required variable.  (NOTE: If given, this
          argument must be named.)

_D_e_t_a_i_l_s:

     The standard naive Bayes classifier (at least this implementation)
     assumes independence of the predictor variables, and gaussian
     distribution (given the target class) of metric predictors.

_V_a_l_u_e:

     An object of class '"naiveBayes"' including components:

 apriori: Class distribution for the dependent variable.

  tables: A list of tables, one for each predictor variable. For each
          categorical variable a table giving, for each attribute
          level, the conditional probabilities given the target class.
          For each numeric variable, a table giving, for each target
          class, mean and standard deviation of the (sub-)variable.

_A_u_t_h_o_r(_s):

     David Meyer david.meyer@ci.tuwien.ac.at

_S_e_e _A_l_s_o:

     'predict.naiveBayes'

_E_x_a_m_p_l_e_s:

     ## Categorical data only:
     data(HouseVotes84)
     model <- naiveBayes(Class ~ ., data = HouseVotes84)
     predict(model, HouseVotes84[1:10,-1])
     predict(model, HouseVotes84[1:10,-1], type = "raw")

     pred <- predict(model, HouseVotes84[,-1])
     table(pred, HouseVotes84$Class)

     ## Example of using a contingency table:
     data(Titanic)
     m <- naiveBayes(Survived ~ ., data = Titanic)
     m
     predict(m, as.data.frame(Titanic)[,1:3])

     ## Example with metric predictors:
     data(iris)
     m <- naiveBayes(Species ~ ., data = iris)
     ## alternatively:
     m <- naiveBayes(iris[,-5], iris[,5])
     m
     table(predict(m, iris[,-5]), iris[,5])

