在插入符号包中使用朴素贝叶斯分类器时的警告 [英] Warnings while using the Naive Bayes Classifier in the Caret Package

查看:237
本文介绍了在插入符号包中使用朴素贝叶斯分类器时的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在插入符号包中运行一个称为Naive Bayes的受监督机器学习分类器。我的数据称为LDA.scores,具有两个分类因子 V4和 G8,以及12个预测变量。我正在使用的代码是由我自己提供的代码在堆栈溢出时由一个好心人改编的(请参阅下面的链接)。该代码确实有效,但是只使用了9个预测变量,而不是数据集中的12个预测变量。当我尝试使用总数据集[2:13]训练Naive Bayes模型时,代码失败。我的下一步是使用数据集中的列的子集(例如[2:9]和[2:10])系统地运行代码,这绝对好。但是,当我尝试使用列[2:11](即列标题修饰)来训练模型时,这是发生警告消息的时间。我不明白为什么该代码适用于列[2:10],但之后却失败(请参阅下面的代码,预热消息和数据)。如果有人可以解决此问题,或者可以通过帮助我理解这些警告消息来提供帮助,那么您的言语将无法表达我的感激之情。我已使用此数据(如下)进行各种分析,但没有任何问题。再次感谢您的帮助。

I am attempting to run a supervised machine learning classifier known as Naive Bayes in the caret Package. My data is called LDA.scores, and has two categorical factors called "V4" and "G8", and 12 predictor variables. The code that I am using was adapted by a kind person on stack overflow from code supplied by myself (see link below).The code does work, however, only 9 predictors were used instead of the 12 predictors in the data-set. When I tried to train the Naive Bayes model with the total data set [2:13], the code failed. My next step was to systematically run the code with a subset of columns from the data-set such as [2:9] and [2:10], which was absolutely fine. However, when I tried to train the model with columns [2:11] (i.e. column heading grooming), this is when the warning messages occurred. I do not understand why the code works for columns [2:10] but fails afterwards (please see the code, warming messages, and data below). If anyone has a solution to this problem or can assist by helping me understand these warning messages, then words cannot express my gratitude. I have used this data (below) for different kinds of analyses and I have not had any issues. Thank you again if you can help.

Naive Bayes Classification task with ROC curve

library(MASS)
library(caret)

set.seed(1234)



构建模型



Build Model

nb_tune <- data.frame(usekernel =TRUE, fL = 0)
nb_mod <- train(x = mydat_resampled[, 2:13], y = as.factor(mydat_resampled[, 1]), method = "nb", trControl = trainControl(method = "cv", classProbs = TRUE), tuneGrid = nb_tune)



警告消息



Warning Messages

Warning messages:
1: In FUN(X[[i]], ...) :
Numerical 0 probability for all classes with observation 3
2: In FUN(X[[i]], ...) :
Numerical 0 probability for all classes with observation 3



模型预测



Model Prediction

nb_pred <- predict(nb_mod, newdata = mydat[ , 2:13], type = "prob")
mydat['nb_pred'] <- nb_pred["G8"]



DATA



DATA

   Family    Swimming Not.Swimming      Running  Not.Running
1      v4 -0.48055680 -0.086292700 -0.157157188 -0.438809944
2      v4  0.12600625 -0.074481895  0.057316151 -0.539013927
3      v4  0.06823834 -0.056765686  0.064711783 -0.539013927
4      v4  0.67480139 -0.050860283  0.153459372 -0.539013927
5      v4  0.64591744 -0.050860283  0.072107416 -0.472211271
6      v4  0.21265812 -0.068576492  0.057316151 -0.071395338
7      v4 -0.01841352 -0.068576492 -0.053618335 -0.071395338
8      v4  0.12600625  0.055436970  0.012942357  0.296019267
9      v4 -0.22060120  0.114491000 -0.038827070  0.563229889
10     v4  0.27042603 -0.021333268  0.049920519 -0.037994010
11     v4  0.03935439 -0.044954880  0.012942357  0.195815284
12     v4 -0.45167284  0.008193747 -0.075805232 -0.171599321
13     v4 -0.04729748 -0.056765686  0.035129254 -0.305204632
14     v4 -0.10506539  0.008193747 -0.046222702  0.062209973
15     v4  0.09712230  0.037720761  0.109085578 -0.104796666
16     v4 -0.07618143  0.014099150 -0.038827070  0.095611301
17     v4  0.29930998  0.108585597  0.057316151  0.028808645
18     v4  0.01047043 -0.074481895  0.020337989 -0.071395338
19     v4 -0.24948516  0.002288344  0.035129254  0.329420595
20     v4 -0.04729748  0.049531567  0.057316151  0.296019267
21     v4 -0.01841352  0.043626164  0.005546724 -0.171599321
22     v4 -0.19171725  0.049531567 -0.016640173 -0.071395338
23     v4 -0.48055680  0.020004552 -0.142365923  0.596631217
24     v4  0.01047043  0.008193747  0.220020063  0.062209973
25     v4 -0.42278889  0.025909955 -0.149761556  0.028808645
26     v4 -0.45167284  0.031815358 -0.134970291 -0.138197994
27     v4 -0.30725307  0.049531567  0.042524886  0.095611301
28     v4  0.24154207 -0.039049477  0.072107416 -0.104796666
29     v4  1.45466817 -0.003617059  0.064711783  0.296019267
30     v4 -0.01841352  0.002288344  0.020337989  0.028808645
31     G8  0.38596185  0.084963985  0.049920519 -0.037994010
32     G8  0.15489021 -0.080387298  0.020337989 -0.338605960
33     G8 -0.04729748  0.067247776  0.138668107  0.129012629
34     G8  0.27042603  0.031815358  0.049920519  0.195815284
35     G8 -0.07618143  0.037720761  0.020337989 -0.037994010
36     G8 -0.10506539  0.025909955 -0.083200864  0.396223251
37     G8 -0.01841352  0.126301805 -0.024035805  0.362821923
38     G8  0.01047043  0.031815358 -0.016640173 -0.138197994
39     G8  0.06823834  0.037720761 -0.038827070  0.262617940
40     G8 -0.16283329 -0.050860283 -0.038827070 -0.405408616
41     G8 -0.01841352 -0.039049477  0.005546724 -0.205000649
42     G8 -0.39390493 -0.003617059 -0.090596497  0.129012629
43     G8 -0.04729748  0.008193747 -0.009244540  0.195815284
44     G8  0.01047043 -0.039049477 -0.016640173 -0.205000649
45     G8  0.01047043 -0.003617059 -0.075805232 -0.004592683
46     G8  0.06823834  0.008193747 -0.090596497 -0.205000649
47     G8 -0.04729748  0.014099150  0.012942357 -0.071395338
48     G8 -0.22060120 -0.015427865 -0.075805232 -0.171599321
49     G8 -0.16283329  0.020004552 -0.061013967 -0.104796666
50     G8 -0.07618143  0.031815358 -0.038827070 -0.138197994
51     G8 -0.22060120  0.020004552 -0.112783394 -0.104796666
52     G8 -0.19171725 -0.033144074 -0.068409599 -0.071395338
53     G8 -0.16283329 -0.039049477 -0.090596497 -0.104796666
54     G8 -0.22060120 -0.009522462 -0.053618335 -0.037994010
55     G8 -0.13394934 -0.003617059 -0.075805232 -0.004592683
56     G8 -0.27836911 -0.044954880 -0.090596497 -0.238401977
57     G8 -0.04729748 -0.050860283  0.064711783  0.028808645
58     G8  0.01047043 -0.044954880  0.012942357 -0.305204632
59     G8  0.12600625 -0.068576492  0.042524886 -0.305204632
60     G8  0.06823834 -0.033144074 -0.061013967 -0.271803305
61     G8  0.06823834 -0.027238671 -0.061013967 -0.037994010
62     G8  0.32819394 -0.068576492  0.064711783 -0.372007288
63     G8  0.32819394  0.014099150  0.175646269  0.095611301
64     G8 -0.27836911  0.002288344 -0.068409599  0.195815284
65     G8  0.18377416  0.025909955  0.027733621  0.162413956
66     G8  0.55926557 -0.009522462  0.042524886  0.229216612
67     G8 -0.19171725 -0.009522462 -0.038827070  0.229216612
68     G8 -0.19171725  0.025909955 -0.009244540  0.396223251
69     G8  0.01047043  0.155828820  0.027733621  0.630032545
70     G8 -0.19171725  0.002288344 -0.031431438  0.463025906
71     G8 -0.01841352 -0.044954880 -0.046222702  0.496427234
72     G8 -0.07618143 -0.015427865 -0.031431438  0.062209973
73     G8 -0.13394934  0.008193747 -0.068409599 -0.071395338
74     G8 -0.39390493  0.037720761 -0.120179026  0.229216612
75     G8 -0.04729748  0.008193747  0.035129254 -0.071395338
76     G8 -0.27836911 -0.015427865 -0.061013967 -0.071395338
77     G8  0.70368535 -0.056765686  0.397515240 -0.205000649
78     G8  0.29930998  0.079058582  0.138668107  0.229216612
79     G8 -0.13394934 -0.056765686  0.020337989 -0.305204632
80     G8  0.21265812  0.025909955  0.035129254  0.396223251
   Family    Fighting Not.Fighting        Resting  Not.Resting
1      v4 -0.67708172 -0.097624192  0.01081204879 -0.770462870
2      v4 -0.58224128 -0.160103675 -0.03398160805  0.773856776
3      v4 -0.11436177 -0.092996082  0.05710879700 -2.593072768
4      v4 -0.34830152 -0.234153433 -0.04063432116 -2.837675606
5      v4 -0.84568695 -0.136963126 -0.13084281035 -1.680828329
6      v4 -0.32933343 -0.157789620 -0.02997847693 -0.947623773
7      v4  0.35984044 -0.157789620  0.12732080268 -0.947623773
8      v4 -0.32511830 -0.023574435 -0.10281705810 -2.607366431
9      v4  1.51478626  0.001880170  0.08155320398 -0.637055341
10     v4  0.11114773 -0.224897213 -0.17932134171 -1.818396455
11     v4  0.27975296 -0.109194467 -0.14338902206  2.170944974
12     v4 -0.89626852 -0.069855533 -0.02058415581 -0.658126752
13     v4  0.12379312 -0.123078796 -0.11528274705 -0.808243774
14     v4  0.66965255 -0.111508522 -0.11764091337  2.377766908
15     v4  1.56536783 -0.143905291  0.04389156236  2.111220276
16     v4  0.56427428 -0.099938247  0.01399844913 -0.322326312
17     v4 -0.71291033 -0.118450687 -0.05755560242  2.218858946
18     v4 -0.75927677  1.519900201  0.04711630687  3.920878638
19     v4 -0.75295407  0.177748344  0.01584280360 -0.304945754
20     v4 -1.00164679  0.108326696  0.09348590900  1.038591535
21     v4 -1.03958296  0.652129604  0.09677967302  1.752268128
22     v4  0.82139726  0.638245274  0.02053612974  0.907465624
23     v4 -1.07541157 -0.072169588 -0.03608286844  1.137774798
24     v4 -1.03115270  0.087500202  0.07805238146 -3.663486997
25     v4 -0.98900139 -0.180930170 -0.00009686695  2.350924346
26     v4 -1.06908888 -0.146219346 -0.02285413055  0.067293462
27     v4 -1.20186549 -0.049029039 -0.00424187149 -1.898454393
28     v4  0.58324237 -0.125392851  0.01446241356 -2.497647463
29     v4 -0.97003330 -0.134649071  0.03187450017 -4.471716512
30     v4  0.22917139 -0.060599313  0.11323315542 -1.465081244
31     G8  0.41042201 -0.086053918 -0.01171898422 -0.232806371
32     G8 -1.11545531 -0.197128554 -0.06499053655 -3.043893581
33     G8 -0.19023412 -0.083739863 -0.07758659568 -2.323908986
34     G8  0.25446217 -0.092996082 -0.07399758157  1.437404886
35     G8 -0.05324237  0.844196163 -0.11503350996  1.079056696
36     G8  0.09007207  0.055103433  0.02167111711  1.110865131
37     G8  1.21129685  1.971140911  0.01904454162  1.404724068
38     G8  0.62539368 -0.111508522  0.05768779393 -1.706664294
39     G8  1.32932051 -0.224897213  0.05555202379  0.736746935
40     G8  0.40199175 -0.187872334 -0.01031175326 -0.005516985
41     G8  0.44625062 -0.160103675 -0.00458313459  1.727170333
42     G8  0.60221046 -0.194814499  0.17430774591  1.685228831
43     G8  0.33665722 -0.053657149  0.00481502094  1.836016918
44     G8 -0.63493041 -0.206384774 -0.00928412956  0.466173920
45     G8 -0.28296700  0.108326696  0.09047589183  1.697173771
46     G8 -0.32722587 -0.164731785  0.08917985896  1.057314221
47     G8 -0.11646933  0.187004564 -0.05671203072  0.933704227
48     G8 -0.10171637  0.025020719 -0.05333390954  0.482480775
49     G8  0.13643851  0.057417488  0.08541446168  0.680713089
50     G8 -0.57802615  0.434608441  0.10140397965  0.090780703
51     G8  0.05002833  0.057417488 -0.02509342995  0.680713089
52     G8 -0.16072820  0.073615872 -0.03698779080 -0.982921741
53     G8 -0.29139726 -0.035144709  0.04609635201 -2.281900378
54     G8  0.13222338 -0.051343094  0.06524159499  0.972089090
55     G8 -0.41152848 -0.134649071  0.08459773090  0.027767791
56     G8  0.68229794 -0.185558279 -0.03239032508 -0.162881500
57     G8 -0.24292325  0.013450444 -0.03208740616 -0.530221948
58     G8 -0.11646933 -0.134649071  0.06264952925 -0.385741863
59     G8 -0.21341734 -0.215640993  0.05241547086 -0.972251823
60     G8 -0.24292325 -0.185558279 -0.03437271856  0.002267358
61     G8 -0.24292325 -0.005061995 -0.03437271856 -1.134447998
62     G8  0.09007207 -0.238781543 -0.06747523863  0.626424009
63     G8 -0.34197883 -0.099938247 -0.01270059491 -0.722750217
64     G8 -0.30825778 -0.167045840  0.10014629095 -0.382722075
65     G8 -0.08696342 -0.208698829 -0.02872845706 -0.356550578
66     G8 -0.81196590  0.048161268 -0.00950652573 -1.851614124
67     G8  0.49683219  0.048161268  0.04867308008 -1.851614124
68     G8 -0.13754498 -0.037458764  0.02486518629  1.731465143
69     G8 -0.48318570  0.161549960 -0.05951115497  0.254319006
70     G8  0.39988418  0.031962884 -0.02353665674  2.043778341
71     G8  0.90148474 -0.102252302 -0.01967923345 -0.289913920
72     G8  0.28396809 -0.123078796 -0.10148651548  1.386940871
73     G8  1.05322945 -0.139277181 -0.00480936518  0.054207713
74     G8  1.24923303 -0.208698829 -0.00098261723  0.594212936
75     G8  0.47154141 -0.118450687 -0.13970798195  1.551821303
76     G8  1.27873894 -0.072169588 -0.00286148145  3.100704184
77     G8  0.05002833 -0.044400929 -0.05492902692  0.327263666
78     G8  1.54218461 -0.030516599  0.10732815358 -1.055195336
79     G8  0.74763247 -0.132335016  0.11660744219 -1.134447998
80     G8  0.11747042 -0.037458764 -0.02016620439  1.730726972
   Family     Hunting  Not.Hunting    Grooming Not Grooming
1      v4 -0.67708172  0.114961983   0.2644238  0.105443109
2      v4 -0.58224128  0.556326739  -1.9467488 -0.249016133
3      v4 -0.11436177  0.326951992   2.1597867 -0.563247851
4      v4 -0.34830152  0.795734469   2.1698228 -0.611969290
5      v4 -0.84568695  0.770046573   0.2554708 -0.230476117
6      v4 -0.32933343  0.736574466   0.1225477 -0.270401826
7      v4  0.35984044  0.215724268   0.1225477  1.057451389
8      v4 -0.32511830 -0.200731013   0.2593696 -0.260830004
9      v4  1.51478626 -2.160535836   0.8687508  1.030589923
10     v4  0.11114773  0.660462182   1.7955299 -0.809959417
11     v4  0.27975296 -0.293709087  -0.8377330 -0.292132450
12     v4 -0.89626852  0.565754284   1.3339454 -0.573854465
13     v4  0.12379312 -0.499644710  -0.5100101 -0.372285683
14     v4  0.66965255  0.080624964  -2.6852985 -0.470590886
15     v4  1.56536783 -4.076143639  -0.8432925  1.657328707
16     v4  0.56427428 -0.127040484  -0.8662526 -0.161145079
17     v4 -0.71291033  0.661240603  -2.1990933 -0.381900622
18     v4 -0.75927677  0.294950237  -3.5062302 -0.121909231
19     v4 -0.75295407  0.548369546  -1.3326746 -0.338568723
20     v4 -1.00164679  0.137622686  -1.7580862 -0.312742050
21     v4 -1.03958296  0.019302681  -2.2730277  0.708985315
22     v4  0.82139726 -0.043057497  -3.1829838 -0.378408200
23     v4 -1.07541157  0.351515502  -0.3762928 -0.304161903
24     v4 -1.03115270 -0.007163636   1.3605877 -0.431053223
25     v4 -0.98900139  0.253780410  -1.1388134 -0.554883286
26     v4 -1.06908888  0.700680605   0.6629041  0.113074697
27     v4 -1.20186549  0.340704098   0.9979915 -0.693545361
28     v4  0.58324237 -1.727041782   1.5589254  0.180163686
29     v4 -0.97003330  0.209410408   1.7613786 -0.258156792
30     v4  0.22917139 -2.441026901   1.3929340  0.276959818
31     G8  0.41042201  0.383257784  -0.5374467  0.165978418
32     G8 -1.11545531 -1.098682982   2.9654839  0.148947473
33     G8 -0.19023412  0.873144122   2.5120581 -0.846910101
34     G8  0.25446217  0.968889915  -0.4130434 -0.938661624
35     G8 -0.05324237  0.936455703  -2.5993065 -0.949914982
36     G8  0.09007207 -0.467815937  -1.0766479  1.474170593
37     G8  1.21129685 -1.239490708  -4.1335895  1.357023559
38     G8  0.62539368  0.177235670   2.4989896  1.393241265
39     G8  1.32932051 -4.736158229  -0.5718146  2.467225606
40     G8  0.40199175  0.342693397   0.5675981  0.648320657
41     G8  0.44625062  0.488950070  -1.6998195  0.709588943
42     G8  0.60221046 -0.415575233  -1.4313741  0.728473890
43     G8  0.33665722  0.353937257  -2.2985148  0.379706002
44     G8 -0.63493041  0.262083568   0.2245685 -0.367629121
45     G8 -0.28296700  0.574316915  -1.0020637  0.280710938
46     G8 -0.32722587  0.323665326  -1.1559252  0.119455912
47     G8 -0.11646933  0.786566398   0.1746772 -0.858206576
48     G8 -0.10171637  0.718065343  -0.2673407 -0.552555005
49     G8  0.13643851  0.584868846  -0.1203383 -0.335378116
50     G8 -0.57802615 -0.053955393   0.6359729  0.057885811
51     G8  0.05002833  0.738563765  -0.1203383 -0.188308359
52     G8 -0.16072820  0.778263240   2.1906890 -0.545138998
53     G8 -0.29139726  0.751018502   1.6039070  0.198100074
54     G8  0.13222338  0.297804447  -0.5217068 -0.514310832
55     G8 -0.41152848  0.102161281   0.3866610 -0.036323341
56     G8  0.68229794  0.371667959   1.6179863 -0.176365139
57     G8 -0.24292325  0.631574111   1.4206594 -0.269668849
58     G8 -0.11646933 -0.004568899   1.6827511  0.003731717
59     G8 -0.21341734  0.214080935   1.0590019  0.036586351
60     G8 -0.24292325  0.796339908   1.2727184 -0.615289246
61     G8 -0.24292325  0.796339908   2.6745838 -0.615289246
62     G8  0.09007207 -0.396720145   0.2644238  0.290800156
63     G8 -0.34197883  0.441985331   1.4545220 -0.520648930
64     G8 -0.30825778 -2.489721464   1.3587105  1.711267220
65     G8 -0.08696342  0.407907785   0.8136610 -0.273333736
66     G8 -0.81196590  0.554423932   1.3666527 -0.594420949
67     G8  0.49683219  0.697912886   1.3666527 -0.446661330
68     G8 -0.13754498  0.491198842  -1.3307974 -0.333825929
69     G8 -0.48318570  0.604848320  -0.1305910 -0.601492025
70     G8  0.39988418  0.773938679  -0.5078441 -0.712559657
71     G8  0.90148474  0.734412186  -0.1166561 -0.548803885
72     G8  0.28396809  1.145505011  -1.3062489 -0.921846260
73     G8  1.05322945  0.616784110   0.9039851 -0.165629176
74     G8  1.24923303  0.329287256   0.3647117  0.111867440
75     G8  0.47154141 -0.016764163  -1.1586689 -0.476713403
76     G8  1.27873894  0.007799347  -3.0386529  0.215087903
77     G8  0.05002833  0.209496900  -1.5080522  0.324560232
78     G8  1.54218461 -5.031179821   1.6811626  2.366893936
79     G8  0.74763247 -0.325105405   1.6851337  1.351590903
80     G8  0.11747042 -0.756350687  -1.3315194  0.375911766

   Family        Other
1      v4  0.019502286
2      v4 -0.290451956
3      v4  0.359948884
4      v4  0.557840914
5      v4  0.117453376
6      v4  0.126645924
7      v4  0.126645924
8      v4  0.196486873
9      v4  0.152780228
10     v4  0.354469789
11     v4 -0.261430968
12     v4  0.176448238
13     v4 -0.007374708
14     v4 -0.557848621
15     v4 -0.213674557
16     v4 -0.005819262
17     v4 -0.470070992
18     v4 -0.786078864
19     v4  0.006063789
20     v4 -0.271842650
21     v4 -0.349418792
22     v4 -0.338096262
23     v4 -0.165119403
24     v4  0.346566439
25     v4 -0.344191931
26     v4  0.074321265
27     v4  0.179825379
28     v4  0.278407054
29     v4  0.593125727
30     v4  0.199177375
31     G8 -0.058900625
32     G8  0.633875622
33     G8  0.428150308
34     G8 -0.206023441
35     G8 -0.436958199
36     G8 -0.291839246
37     G8 -0.907641911
38     G8  0.448567295
39     G8 -0.127186127
40     G8  0.024715134
41     G8 -0.416345030
42     G8 -0.330697382
43     G8 -0.469720666
44     G8 -0.047494017
45     G8 -0.301732446
46     G8 -0.138901021
47     G8  0.098101379
48     G8 -0.002063769
49     G8 -0.028324190
50     G8  0.071630763
51     G8 -0.028324190
52     G8  0.295110588
53     G8  0.347112947
54     G8 -0.083577573
55     G8 -0.036886152
56     G8  0.189045953
57     G8  0.467596992
58     G8  0.303378276
59     G8  0.218879697
60     G8  0.092005711
61     G8  0.270111340
62     G8 -0.012909856
63     G8  0.262292068
64     G8  0.107125772
65     G8  0.123422927
66     G8  0.299426602
67     G8  0.299426602
68     G8 -0.326871824
69     G8 -0.022088391
70     G8 -0.428508341
71     G8 -0.014675497
72     G8 -0.114462294
73     G8  0.087227267
74     G8 -0.031519161
75     G8 -0.159318008
76     G8 -0.397875854
77     G8  0.101520559
78     G8  0.244481505
79     G8  0.529968994
80     G8 -0.326619590               


推荐答案

<我想我拼凑了一些问题。此响应部分有助于显示如何创建可重现的示例(基于已提供的建议)并在回答问题上取得一些进展

I think I pieced together some of the problem. This response is partly to help show how to create a reproducible example (based on suggestions already provided) and to make some progress in answering the question

步骤1:提供数据

下面直接是 dput(mydat)生成的输出。可以将整个块复制到R中,并立即看到 mydat 数据框,而不必尝试进行大量手动加载和编辑。

Directly below is the output generated from dput(mydat). One can copy this entire block into R and instantly see the mydat data frame, rather than try to finagle with a bunch of manual loading and editing.

mydat <- structure(list(Family = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("G8", "v4"), class = "factor"), 
    Swimming = c(-0.4805568, 0.12600625, 0.06823834, 0.67480139, 
    0.64591744, 0.21265812, -0.01841352, 0.12600625, -0.2206012, 
    0.27042603, 0.03935439, -0.45167284, -0.04729748, -0.10506539, 
    0.0971223, -0.07618143, 0.29930998, 0.01047043, -0.24948516, 
    -0.04729748, -0.01841352, -0.19171725, -0.4805568, 0.01047043, 
    -0.42278889, -0.45167284, -0.30725307, 0.24154207, 1.45466817, 
    -0.01841352, 0.38596185, 0.15489021, -0.04729748, 0.27042603, 
    -0.07618143, -0.10506539, -0.01841352, 0.01047043, 0.06823834, 
    -0.16283329, -0.01841352, -0.39390493, -0.04729748, 0.01047043, 
    0.01047043, 0.06823834, -0.04729748, -0.2206012, -0.16283329, 
    -0.07618143, -0.2206012, -0.19171725, -0.16283329, -0.2206012, 
    -0.13394934, -0.27836911, -0.04729748, 0.01047043, 0.12600625, 
    0.06823834, 0.06823834, 0.32819394, 0.32819394, -0.27836911, 
    0.18377416, 0.55926557, -0.19171725, -0.19171725, 0.01047043, 
    -0.19171725, -0.01841352, -0.07618143, -0.13394934, -0.39390493, 
    -0.04729748, -0.27836911, 0.70368535, 0.29930998, -0.13394934, 
    0.21265812), Not.Swimming = c(-0.0862927, -0.074481895, -0.056765686, 
    -0.050860283, -0.050860283, -0.068576492, -0.068576492, 0.05543697, 
    0.114491, -0.021333268, -0.04495488, 0.008193747, -0.056765686, 
    0.008193747, 0.037720761, 0.01409915, 0.108585597, -0.074481895, 
    0.002288344, 0.049531567, 0.043626164, 0.049531567, 0.020004552, 
    0.008193747, 0.025909955, 0.031815358, 0.049531567, -0.039049477, 
    -0.003617059, 0.002288344, 0.084963985, -0.080387298, 0.067247776, 
    0.031815358, 0.037720761, 0.025909955, 0.126301805, 0.031815358, 
    0.037720761, -0.050860283, -0.039049477, -0.003617059, 0.008193747, 
    -0.039049477, -0.003617059, 0.008193747, 0.01409915, -0.015427865, 
    0.020004552, 0.031815358, 0.020004552, -0.033144074, -0.039049477, 
    -0.009522462, -0.003617059, -0.04495488, -0.050860283, -0.04495488, 
    -0.068576492, -0.033144074, -0.027238671, -0.068576492, 0.01409915, 
    0.002288344, 0.025909955, -0.009522462, -0.009522462, 0.025909955, 
    0.15582882, 0.002288344, -0.04495488, -0.015427865, 0.008193747, 
    0.037720761, 0.008193747, -0.015427865, -0.056765686, 0.079058582, 
    -0.056765686, 0.025909955), Running = c(-0.157157188, 0.057316151, 
    0.064711783, 0.153459372, 0.072107416, 0.057316151, -0.053618335, 
    0.012942357, -0.03882707, 0.049920519, 0.012942357, -0.075805232, 
    0.035129254, -0.046222702, 0.109085578, -0.03882707, 0.057316151, 
    0.020337989, 0.035129254, 0.057316151, 0.005546724, -0.016640173, 
    -0.142365923, 0.220020063, -0.149761556, -0.134970291, 0.042524886, 
    0.072107416, 0.064711783, 0.020337989, 0.049920519, 0.020337989, 
    0.138668107, 0.049920519, 0.020337989, -0.083200864, -0.024035805, 
    -0.016640173, -0.03882707, -0.03882707, 0.005546724, -0.090596497, 
    -0.00924454, -0.016640173, -0.075805232, -0.090596497, 0.012942357, 
    -0.075805232, -0.061013967, -0.03882707, -0.112783394, -0.068409599, 
    -0.090596497, -0.053618335, -0.075805232, -0.090596497, 0.064711783, 
    0.012942357, 0.042524886, -0.061013967, -0.061013967, 0.064711783, 
    0.175646269, -0.068409599, 0.027733621, 0.042524886, -0.03882707, 
    -0.00924454, 0.027733621, -0.031431438, -0.046222702, -0.031431438, 
    -0.068409599, -0.120179026, 0.035129254, -0.061013967, 0.39751524, 
    0.138668107, 0.020337989, 0.035129254), Not.Running = c(-0.438809944, 
    -0.539013927, -0.539013927, -0.539013927, -0.472211271, -0.071395338, 
    -0.071395338, 0.296019267, 0.563229889, -0.03799401, 0.195815284, 
    -0.171599321, -0.305204632, 0.062209973, -0.104796666, 0.095611301, 
        0.028808645, -0.071395338, 0.329420595, 0.296019267, -0.171599321, 
        -0.071395338, 0.596631217, 0.062209973, 0.028808645, -0.138197994, 
        0.095611301, -0.104796666, 0.296019267, 0.028808645, -0.03799401, 
        -0.33860596, 0.129012629, 0.195815284, -0.03799401, 0.396223251, 
        0.362821923, -0.138197994, 0.26261794, -0.405408616, -0.205000649, 
        0.129012629, 0.195815284, -0.205000649, -0.004592683, -0.205000649, 
        -0.071395338, -0.171599321, -0.104796666, -0.138197994, -0.104796666, 
        -0.071395338, -0.104796666, -0.03799401, -0.004592683, -0.238401977, 
        0.028808645, -0.305204632, -0.305204632, -0.271803305, -0.03799401, 
        -0.372007288, 0.095611301, 0.195815284, 0.162413956, 0.229216612, 
        0.229216612, 0.396223251, 0.630032545, 0.463025906, 0.496427234, 
        0.062209973, -0.071395338, 0.229216612, -0.071395338, -0.071395338, 
        -0.205000649, 0.229216612, -0.305204632, 0.396223251), Fighting = c(-0.67708172, 
        -0.58224128, -0.11436177, -0.34830152, -0.84568695, -0.32933343, 
        0.35984044, -0.3251183, 1.51478626, 0.11114773, 0.27975296, 
        -0.89626852, 0.12379312, 0.66965255, 1.56536783, 0.56427428, 
        -0.71291033, -0.75927677, -0.75295407, -1.00164679, -1.03958296, 
        0.82139726, -1.07541157, -1.0311527, -0.98900139, -1.06908888, 
        -1.20186549, 0.58324237, -0.9700333, 0.22917139, 0.41042201, 
        -1.11545531, -0.19023412, 0.25446217, -0.05324237, 0.09007207, 
        1.21129685, 0.62539368, 1.32932051, 0.40199175, 0.44625062, 
        0.60221046, 0.33665722, -0.63493041, -0.282967, -0.32722587, 
        -0.11646933, -0.10171637, 0.13643851, -0.57802615, 0.05002833, 
        -0.1607282, -0.29139726, 0.13222338, -0.41152848, 0.68229794, 
        -0.24292325, -0.11646933, -0.21341734, -0.24292325, -0.24292325, 
        0.09007207, -0.34197883, -0.30825778, -0.08696342, -0.8119659, 
        0.49683219, -0.13754498, -0.4831857, 0.39988418, 0.90148474, 
        0.28396809, 1.05322945, 1.24923303, 0.47154141, 1.27873894, 
        0.05002833, 1.54218461, 0.74763247, 0.11747042), Not.Fighting = c(-0.097624192, 
        -0.160103675, -0.092996082, -0.234153433, -0.136963126, -0.15778962, 
        -0.15778962, -0.023574435, 0.00188017, -0.224897213, -0.109194467, 
        -0.069855533, -0.123078796, -0.111508522, -0.143905291, -0.099938247, 
        -0.118450687, 1.519900201, 0.177748344, 0.108326696, 0.652129604, 
        0.638245274, -0.072169588, 0.087500202, -0.18093017, -0.146219346, 
        -0.049029039, -0.125392851, -0.134649071, -0.060599313, -0.086053918, 
        -0.197128554, -0.083739863, -0.092996082, 0.844196163, 0.055103433, 
        1.971140911, -0.111508522, -0.224897213, -0.187872334, -0.160103675, 
        -0.194814499, -0.053657149, -0.206384774, 0.108326696, -0.164731785, 
        0.187004564, 0.025020719, 0.057417488, 0.434608441, 0.057417488, 
        0.073615872, -0.035144709, -0.051343094, -0.134649071, -0.185558279, 
        0.013450444, -0.134649071, -0.215640993, -0.185558279, -0.005061995, 
        -0.238781543, -0.099938247, -0.16704584, -0.208698829, 0.048161268, 
        0.048161268, -0.037458764, 0.16154996, 0.031962884, -0.102252302, 
        -0.123078796, -0.139277181, -0.208698829, -0.118450687, -0.072169588, 
        -0.044400929, -0.030516599, -0.132335016, -0.037458764), 
        Resting = c(0.01081204879, -0.03398160805, 0.057108797, -0.04063432116, 
        -0.13084281035, -0.02997847693, 0.12732080268, -0.1028170581, 
        0.08155320398, -0.17932134171, -0.14338902206, -0.02058415581, 
        -0.11528274705, -0.11764091337, 0.04389156236, 0.01399844913, 
        -0.05755560242, 0.04711630687, 0.0158428036, 0.093485909, 
        0.09677967302, 0.02053612974, -0.03608286844, 0.07805238146, 
        -9.686695e-05, -0.02285413055, -0.00424187149, 0.01446241356, 
        0.03187450017, 0.11323315542, -0.01171898422, -0.06499053655, 
        -0.07758659568, -0.07399758157, -0.11503350996, 0.02167111711, 
        0.01904454162, 0.05768779393, 0.05555202379, -0.01031175326, 
        -0.00458313459, 0.17430774591, 0.00481502094, -0.00928412956, 
        0.09047589183, 0.08917985896, -0.05671203072, -0.05333390954, 
        0.08541446168, 0.10140397965, -0.02509342995, -0.0369877908, 
        0.04609635201, 0.06524159499, 0.0845977309, -0.03239032508, 
        -0.03208740616, 0.06264952925, 0.05241547086, -0.03437271856, 
        -0.03437271856, -0.06747523863, -0.01270059491, 0.10014629095, 
        -0.02872845706, -0.00950652573, 0.04867308008, 0.02486518629, 
        -0.05951115497, -0.02353665674, -0.01967923345, -0.10148651548, 
        -0.00480936518, -0.00098261723, -0.13970798195, -0.00286148145, 
        -0.05492902692, 0.10732815358, 0.11660744219, -0.02016620439
        ), Not.Resting = c(-0.77046287, 0.773856776, -2.593072768, 
        -2.837675606, -1.680828329, -0.947623773, -0.947623773, -2.607366431, 
        -0.637055341, -1.818396455, 2.170944974, -0.658126752, -0.808243774, 
        2.377766908, 2.111220276, -0.322326312, 2.218858946, 3.920878638, 
        -0.304945754, 1.038591535, 1.752268128, 0.907465624, 1.137774798, 
        -3.663486997, 2.350924346, 0.067293462, -1.898454393, -2.497647463, 
        -4.471716512, -1.465081244, -0.232806371, -3.043893581, -2.323908986, 
        1.437404886, 1.079056696, 1.110865131, 1.404724068, -1.706664294, 
        0.736746935, -0.005516985, 1.727170333, 1.685228831, 1.836016918, 
        0.46617392, 1.697173771, 1.057314221, 0.933704227, 0.482480775, 
        0.680713089, 0.090780703, 0.680713089, -0.982921741, -2.281900378, 
        0.97208909, 0.027767791, -0.1628815, -0.530221948, -0.385741863, 
        -0.972251823, 0.002267358, -1.134447998, 0.626424009, -0.722750217, 
        -0.382722075, -0.356550578, -1.851614124, -1.851614124, 1.731465143, 
        0.254319006, 2.043778341, -0.28991392, 1.386940871, 0.054207713, 
        0.594212936, 1.551821303, 3.100704184, 0.327263666, -1.055195336, 
        -1.134447998, 1.730726972), Hunting = c(-0.67708172, -0.58224128, 
        -0.11436177, -0.34830152, -0.84568695, -0.32933343, 0.35984044, 
        -0.3251183, 1.51478626, 0.11114773, 0.27975296, -0.89626852, 
        0.12379312, 0.66965255, 1.56536783, 0.56427428, -0.71291033, 
        -0.75927677, -0.75295407, -1.00164679, -1.03958296, 0.82139726, 
        -1.07541157, -1.0311527, -0.98900139, -1.06908888, -1.20186549, 
        0.58324237, -0.9700333, 0.22917139, 0.41042201, -1.11545531, 
        -0.19023412, 0.25446217, -0.05324237, 0.09007207, 1.21129685, 
        0.62539368, 1.32932051, 0.40199175, 0.44625062, 0.60221046, 
        0.33665722, -0.63493041, -0.282967, -0.32722587, -0.11646933, 
        -0.10171637, 0.13643851, -0.57802615, 0.05002833, -0.1607282, 
        -0.29139726, 0.13222338, -0.41152848, 0.68229794, -0.24292325, 
        -0.11646933, -0.21341734, -0.24292325, -0.24292325, 0.09007207, 
        -0.34197883, -0.30825778, -0.08696342, -0.8119659, 0.49683219, 
        -0.13754498, -0.4831857, 0.39988418, 0.90148474, 0.28396809, 
        1.05322945, 1.24923303, 0.47154141, 1.27873894, 0.05002833, 
        1.54218461, 0.74763247, 0.11747042), Not.Hunting = c(-0.097624192, 
        -0.160103675, -0.092996082, -0.234153433, -0.136963126, -0.15778962, 
        -0.15778962, -0.023574435, 0.00188017, -0.224897213, -0.109194467, 
        -0.069855533, -0.123078796, -0.111508522, -0.143905291, -0.099938247, 
        -0.118450687, 1.519900201, 0.177748344, 0.108326696, 0.652129604, 
        0.638245274, -0.072169588, 0.087500202, -0.18093017, -0.146219346, 
        -0.049029039, -0.125392851, -0.134649071, -0.060599313, -0.086053918, 
        -0.197128554, -0.083739863, -0.092996082, 0.844196163, 0.055103433, 
        1.971140911, -0.111508522, -0.224897213, -0.187872334, -0.160103675, 
        -0.194814499, -0.053657149, -0.206384774, 0.108326696, -0.164731785, 
        0.187004564, 0.025020719, 0.057417488, 0.434608441, 0.057417488, 
        0.073615872, -0.035144709, -0.051343094, -0.134649071, -0.185558279, 
        0.013450444, -0.134649071, -0.215640993, -0.185558279, -0.005061995, 
        -0.238781543, -0.099938247, -0.16704584, -0.208698829, 0.048161268, 
        0.048161268, -0.037458764, 0.16154996, 0.031962884, -0.102252302, 
        -0.123078796, -0.139277181, -0.208698829, -0.118450687, -0.072169588, 
        -0.044400929, -0.030516599, -0.132335016, -0.037458764), 
        Grooming = c(0.01081204879, -0.03398160805, 0.057108797, 
        -0.04063432116, -0.13084281035, -0.02997847693, 0.12732080268, 
        -0.1028170581, 0.08155320398, -0.17932134171, -0.14338902206, 
        -0.02058415581, -0.11528274705, -0.11764091337, 0.04389156236, 
        0.01399844913, -0.05755560242, 0.04711630687, 0.0158428036, 
        0.093485909, 0.09677967302, 0.02053612974, -0.03608286844, 
        0.07805238146, -9.686695e-05, -0.02285413055, -0.00424187149, 
        0.01446241356, 0.03187450017, 0.11323315542, -0.01171898422, 
        -0.06499053655, -0.07758659568, -0.07399758157, -0.11503350996, 
        0.02167111711, 0.01904454162, 0.05768779393, 0.05555202379, 
        -0.01031175326, -0.00458313459, 0.17430774591, 0.00481502094, 
        -0.00928412956, 0.09047589183, 0.08917985896, -0.05671203072, 
        -0.05333390954, 0.08541446168, 0.10140397965, -0.02509342995, 
        -0.0369877908, 0.04609635201, 0.06524159499, 0.0845977309, 
        -0.03239032508, -0.03208740616, 0.06264952925, 0.05241547086, 
        -0.03437271856, -0.03437271856, -0.06747523863, -0.01270059491, 
        0.10014629095, -0.02872845706, -0.00950652573, 0.04867308008, 
        0.02486518629, -0.05951115497, -0.02353665674, -0.01967923345, 
        -0.10148651548, -0.00480936518, -0.00098261723, -0.13970798195, 
        -0.00286148145, -0.05492902692, 0.10732815358, 0.11660744219, 
        -0.02016620439), Not.Grooming = c(-0.77046287, 0.773856776, 
        -2.593072768, -2.837675606, -1.680828329, -0.947623773, -0.947623773, 
        -2.607366431, -0.637055341, -1.818396455, 2.170944974, -0.658126752, 
        -0.808243774, 2.377766908, 2.111220276, -0.322326312, 2.218858946, 
        3.920878638, -0.304945754, 1.038591535, 1.752268128, 0.907465624, 
        1.137774798, -3.663486997, 2.350924346, 0.067293462, -1.898454393, 
        -2.497647463, -4.471716512, -1.465081244, -0.232806371, -3.043893581, 
        -2.323908986, 1.437404886, 1.079056696, 1.110865131, 1.404724068, 
        -1.706664294, 0.736746935, -0.005516985, 1.727170333, 1.685228831, 
        1.836016918, 0.46617392, 1.697173771, 1.057314221, 0.933704227, 
        0.482480775, 0.680713089, 0.090780703, 0.680713089, -0.982921741, 
        -2.281900378, 0.97208909, 0.027767791, -0.1628815, -0.530221948, 
        -0.385741863, -0.972251823, 0.002267358, -1.134447998, 0.626424009, 
        -0.722750217, -0.382722075, -0.356550578, -1.851614124, -1.851614124, 
        1.731465143, 0.254319006, 2.043778341, -0.28991392, 1.386940871, 
        0.054207713, 0.594212936, 1.551821303, 3.100704184, 0.327263666, 
        -1.055195336, -1.134447998, 1.730726972), Other = c(0.019502286, 
        -0.290451956, 0.359948884, 0.557840914, 0.117453376, 0.126645924, 
        0.126645924, 0.196486873, 0.152780228, 0.354469789, -0.261430968, 
        0.176448238, -0.007374708, -0.557848621, -0.213674557, -0.005819262, 
        -0.470070992, -0.786078864, 0.006063789, -0.27184265, -0.349418792, 
        -0.338096262, -0.165119403, 0.346566439, -0.344191931, 0.074321265, 
        0.179825379, 0.278407054, 0.593125727, 0.199177375, -0.058900625, 
        0.633875622, 0.428150308, -0.206023441, -0.436958199, -0.291839246, 
        -0.907641911, 0.448567295, -0.127186127, 0.024715134, -0.41634503, 
        -0.330697382, -0.469720666, -0.047494017, -0.301732446, -0.138901021, 
        0.098101379, -0.002063769, -0.02832419, 0.071630763, -0.02832419, 
        0.295110588, 0.347112947, -0.083577573, -0.036886152, 0.189045953, 
        0.467596992, 0.303378276, 0.218879697, 0.092005711, 0.27011134, 
        -0.012909856, 0.262292068, 0.107125772, 0.123422927, 0.299426602, 
        0.299426602, -0.326871824, -0.022088391, -0.428508341, -0.014675497, 
        -0.114462294, 0.087227267, -0.031519161, -0.159318008, -0.397875854, 
        0.101520559, 0.244481505, 0.529968994, -0.32661959)), .Names = c("Family", 
    "Swimming", "Not.Swimming", "Running", "Not.Running", "Fighting", 
    "Not.Fighting", "Resting", "Not.Resting", "Hunting", "Not.Hunting", 
    "Grooming", "Not.Grooming", "Other"), class = "data.frame", row.names = c(NA, 
    -80L))

Note that this object is very large. You will generally get more (and better) responses if you provide minimal code. This isn’t always possible, but in my experience most people don’t want to copy/paste very large objects.

Note that this object is very large. You will generally get more (and better) responses if you provide minimal code. This isn't always possible, but in my experience most people don't want to copy/paste very large objects.

Step 2: After providing the data, supply all of the code needed, in sequence, before the function that generates the warning/error/message

Step 2: After providing the data, supply all of the code needed, in sequence, before the function that generates the warning/error/message

Your post linked to another post that defined mydat_resampled. Don’t force posters to manually piece this information together from multiple posts - just provide all of the code needed in one post.

Your post linked to another post that defined mydat_resampled. Don't force posters to manually piece this information together from multiple posts - just provide all of the code needed in one post.

# Randomly permute the data before subsetting
set.seed(1234)
mydat_idx <- sample(1:nrow(mydat), replace = FALSE)
mydat <- mydat[mydat_idx, ]

require(caret)
mydat_resampled_idx <- createDataPartition(mydat_idx, times = 1, p = 0.7, list = FALSE)
mydat_resampled <- mydat[mydat_resampled_idx, ] # Training portion of the data

Step 3: Make it clear to readers which line of code is generating the error

These lines do not produce a warning

These lines do not produce a warning

nb_tune <- data.frame(usekernel =TRUE, fL = 0)

set.seed(1234)
nb_mod <- train(x = mydat_resampled[, 2:13], y = as.factor(mydat_resampled[, 1]), 
    method = "nb", trControl = trainControl(method = "cv", classProbs = 
    TRUE), tuneGrid = nb_tune)

But changing 2:13 to 2:14 produces a warning

But changing 2:13 to 2:14 produces a warning

set.seed(1234)
nb_mod <- train(x = mydat_resampled[, 2:14], y = as.factor(mydat_resampled[, 1]), 
    method = "nb", trControl = trainControl(method = "cv", classProbs = 
    TRUE), tuneGrid = nb_tune)

Warning messages:
1: In FUN(X[[i]], ...) :
  Numerical 0 probability for all classes with observation 2
2: In FUN(X[[i]], ...) :
  Numerical 0 probability for all classes with observation 2

As far as the answer goes, user20650’s link provides the most likely explanation - that observation 2 is probably an outlier. As a result, the probability that this observation is 0 for both v4 and G8.

As far as the answer goes, user20650's link provides the most likely explanation - that observation 2 is probably an outlier. As a result, the probability that this observation is 0 for both v4 and G8.

This is not an error or indication that the code is ’wrong’, it is just information to let you know that one of your observations is producing some unusual probabilities - something you may want to examine in either your data or modeling approach.

This is not an error or indication that the code is 'wrong', it is just information to let you know that one of your observations is producing some unusual probabilities - something you may want to examine in either your data or modeling approach.

这篇关于在插入符号包中使用朴素贝叶斯分类器时的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆