naive bayes-Warning message: in date.matrix (newdata): NAs introduced by coercion
I managed to run the naive Bayes algorithm in R, but I am finding problems to make the confusion matrix of the result. This is the message I receive after performing the prediction with the command predict
:
Warning message: in data.matrix (newdata): NAs introduced by coercion "
When adding type= ' raw ' it runs, but when trying to make the confusion array, I get the following error:
Error in table(anatelteste cond condition, prediction) : all arguments must have the same length
This is the code I'm running:
library(e1071)
anatel <- read_csv("anatel.csv", locale = locale(encoding = "ISO-8859-1"))
amostra <- sample(2, 454, replace = T, prob = c(0.7, 0.3))
anatelTreino <- anatel[amostra == 1,]
anatelteste <- anatel[amostra ==2,]
dim(anatelTreino)
dim(anatelteste)
modelo <- naiveBayes(Condicao ~ GrupoEconNorm + CanalEntrada + Tipo + Servico
Modalidade + Motivo, anatelTreino)
modelo
class(modelo)
predicao <- predict(modelo, anatelteste)
## quando eu chego aqui ocorre problemas de NA
Warning messages:
##In data.matrix(newdata) : NAs introduced by coercion
## eu usei type='raw' e consegui proseguir porem nao consigo fazer a tabela de confusao
predicao <- predict(modelo, anatelteste, type='raw')
predicao
confusao <- table(anatelteste$Condicao, predicao)
Error in table(anatelteste$Condicao, predicao): todos os argumentos devem ter o mesmo comprimento
CanalEntrada Condicao GrupoEconNorm Tipo Servico Modalidade Motivo
<chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 Atendimento Pessoal Encerrada Anatel Reclamação Móvel Pessoal Pós-Pago Cobrança
2 Atendimento Pessoal Encerrada OI Reclamação Móvel Pessoal Pós-Pago Cancelamento
3 Atendimento Pessoal Encerrada OI Reclamação Serviço Telefônico Fixo Comutado -~ Local Serviços Adicion~
4 Atendimento Pessoal Encerrada VIVO Reclamação Móvel Pessoal Pós-Pago Bloqueio
5 Atendimento Pessoal Encerrada VIVO Reclamação Móvel Pessoal Pós-Pago Cobrança
6 Atendimento Pessoal Reaberta VIVO Reclamação Móvel Pessoal Pré-Pago Cancelamento
1
Author: Marcus Nunes, 2019-05-21