<h4 dir="auto">Describe the bug</h4>
<p dir="auto"><a href="https://scikit-learn.org/stable/modules/generated/sklearn.naive_bayes.CategoricalNB.html#sklearn.naive_bayes.CategoricalNB" rel="nofollow">https://scikit-learn.org/stable/modules/generated/sklearn.naive_bayes.CategoricalNB.html#sklearn.naive_bayes.CategoricalNB</a></p>
<p dir="auto">NB can  not treat new values in test data<br>
it is bug since real data has new values</p>
<h4 dir="auto">Description</h4>
<p dir="auto">Calling predict() / predict_proba() / predict_log_proba() on CategoricalNB model throws IndexError.</p>
<h4 dir="auto">Steps/Code to Reproduce</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import numpy as np
from sklearn.datasets import make_classification
from sklearn.naive_bayes import CategoricalNB
from sklearn.model_selection import train_test_split

X, y = make_classification(n_features=10, n_classes=3, n_samples=1000, random_state=42,
                                             n_redundant=0, n_informative=6)
X = np.abs(X.astype(np.int))
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=42)
model = CategoricalNB().fit(X_train, y_train)

model.predict(X_test)"><pre class="notranslate"><code class="notranslate">import numpy as np
from sklearn.datasets import make_classification
from sklearn.naive_bayes import CategoricalNB
from sklearn.model_selection import train_test_split

X, y = make_classification(n_features=10, n_classes=3, n_samples=1000, random_state=42,
                                             n_redundant=0, n_informative=6)
X = np.abs(X.astype(np.int))
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=42)
model = CategoricalNB().fit(X_train, y_train)

model.predict(X_test)
</code></pre></div>
<h4 dir="auto">Expected Results</h4>
<p dir="auto">Predictions for X_test(integer labels).</p>
<h4 dir="auto">Actual Results</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
&lt;ipython-input-3-551bb8080923&gt; in &lt;module&gt;
     10 model = CategoricalNB().fit(X_train, y_train)
     11 
---&gt; 12 model.predict(X_test)

~/Documents/MachineLearning/onnx_projects/skl_env/lib/python3.6/site-packages/sklearn/naive_bayes.py in predict(self, X)
     75         check_is_fitted(self)
     76         X = self._check_X(X)
---&gt; 77         jll = self._joint_log_likelihood(X)
     78         return self.classes_[np.argmax(jll, axis=1)]
     79 

~/Documents/MachineLearning/onnx_projects/skl_env/lib/python3.6/site-packages/sklearn/naive_bayes.py in _joint_log_likelihood(self, X)
   1217         for i in range(self.n_features_):
   1218             indices = X[:, i]
-&gt; 1219             jll += self.feature_log_prob_[i][:, indices].T
   1220         total_ll = jll + self.class_log_prior_
   1221         return total_ll

IndexError: index 5 is out of bounds for axis 1 with size 5"><pre class="notranslate"><code class="notranslate">---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
&lt;ipython-input-3-551bb8080923&gt; in &lt;module&gt;
     10 model = CategoricalNB().fit(X_train, y_train)
     11 
---&gt; 12 model.predict(X_test)

~/Documents/MachineLearning/onnx_projects/skl_env/lib/python3.6/site-packages/sklearn/naive_bayes.py in predict(self, X)
     75         check_is_fitted(self)
     76         X = self._check_X(X)
---&gt; 77         jll = self._joint_log_likelihood(X)
     78         return self.classes_[np.argmax(jll, axis=1)]
     79 

~/Documents/MachineLearning/onnx_projects/skl_env/lib/python3.6/site-packages/sklearn/naive_bayes.py in _joint_log_likelihood(self, X)
   1217         for i in range(self.n_features_):
   1218             indices = X[:, i]
-&gt; 1219             jll += self.feature_log_prob_[i][:, indices].T
   1220         total_ll = jll + self.class_log_prior_
   1221         return total_ll

IndexError: index 5 is out of bounds for axis 1 with size 5
</code></pre></div>
<h4 dir="auto">Versions</h4>
<p dir="auto">System:<br>
python: 3.6.8 (v3.6.8:3c6b436a57, Dec 24 2018, 02:04:31)  [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]<br>
executable: /Users/prroy/Documents/MachineLearning/onnx_projects/skl_env/bin/python3<br>
machine: Darwin-19.2.0-x86_64-i386-64bit</p>
<p dir="auto">Python dependencies:<br>
pip: 18.1<br>
setuptools: 40.6.2<br>
sklearn: 0.22.1<br>
numpy: 1.18.0<br>
scipy: 1.4.1<br>
Cython: 0.29.14<br>
pandas: 0.25.3<br>
matplotlib: None<br>
joblib: 0.14.1</p>
<p dir="auto">Built with OpenMP: True</p>