Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R(e1071)中的朴素贝叶斯分类器的行为不符合预期(简单示例)_R_Machine Learning_Statistics_Classification_Naivebayes - Fatal编程技术网

R(e1071)中的朴素贝叶斯分类器的行为不符合预期(简单示例)

R(e1071)中的朴素贝叶斯分类器的行为不符合预期(简单示例),r,machine-learning,statistics,classification,naivebayes,R,Machine Learning,Statistics,Classification,Naivebayes,我不明白为什么会出现以下简单的例子: genre <- c('ROMANCE', 'ROMANCE','ROMANCE', 'ACTION', 'ACTION', 'ACTION') explosions <- c('NO', 'NO', 'NO', 'YES', 'YES', 'YES') likeit <- c('DISLIKE', 'DISLIKE', 'DISLIKE', 'LIKE', 'LIKE', 'LIKE') df <- data.frame(genr

我不明白为什么会出现以下简单的例子:

genre <- c('ROMANCE', 'ROMANCE','ROMANCE', 'ACTION', 'ACTION', 'ACTION')
explosions <- c('NO', 'NO', 'NO', 'YES', 'YES', 'YES')
likeit <- c('DISLIKE', 'DISLIKE', 'DISLIKE', 'LIKE', 'LIKE', 'LIKE')

df <- data.frame(genre, explosions)
df[] <- lapply(df, factor)
df

model <- naiveBayes(df, as.factor(likeit))
model

p_genre <- factor('ACTION')
p_explosions <- factor('YES')
pred <- data.frame(genre=p_genre, explosions=p_explosions)
pred
model
predict(model, pred, type='raw')

对于一部有爆炸的动作片来说,问题1是不合适的。

是你的因素被错误地处理了

如果您执行以下操作,它将按预期工作:

p_genre <- factor('ACTION', c('ACTION','ROMANCE'))
p_explosions <- factor('YES', c('NO', 'YES'))
pred <- data.frame(genre=p_genre, explosions=p_explosions)
predict(model, pred, type='raw')

是您的因素处理不当

如果您执行以下操作,它将按预期工作:

p_genre <- factor('ACTION', c('ACTION','ROMANCE'))
p_explosions <- factor('YES', c('NO', 'YES'))
pred <- data.frame(genre=p_genre, explosions=p_explosions)
predict(model, pred, type='raw')
         DISLIKE     LIKE
[1,] 9.99999e-07 0.999999