<h4 dir="auto">Description</h4>
<p dir="auto"><a href="https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py#L53">https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/naive_bayes.py#L53</a></p>
<p dir="auto">The predict() method defined here doesn't do the input validation by calling<br>
<code class="notranslate">X = check_array(X)</code></p>
<p dir="auto">Which then results in a different difficult to understand error.</p>
<h4 dir="auto">Steps/Code to Reproduce</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import pandas as pd
import numpy as np
from sklearn.naive_bayes import GaussianNB


data = [[418241,442351,2,1905,2,2,2,1,1,1,38,7,2 ],
[424993,432898,2,1615,1,2,2,1,1,2,50,1,1 ],
[431159,436397,2,1645,1,2,1,1,1,1,26,1,1 ],
[431159,436397,2,1645,1,2,1,1,2,2,22,1,1 ],
[439313,432376,2,956,2,1,1,1,1,1,57,2,1 ],
[426994,439957,2,1115,2,2,1,1,1,1,59,2,2 ],
[427813,431257,1,1352,3,1,1,1,1,2,53,1,2 ],
[431496,432727,2,2015,1,1,2,3,2,2,22,1,1 ],
[431880,430498,2,1110,3,1,1,1,2,2,20,1,1]]

data = np.array(data).reshape(-1,13)

y = data[:,12]
X = data[:,0:12]

model = GaussianNB()
model.fit(X, y)

X_test = ['427750', '426259', '2', '1610', '2', '1', '2', '1', '4', '1', '47', '2']
X_test = np.reshape(X_test, [1, -1])
y_pred = model.predict(X_test)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">from</span> <span class="pl-s1">sklearn</span>.<span class="pl-s1">naive_bayes</span> <span class="pl-k">import</span> <span class="pl-v">GaussianNB</span>


<span class="pl-s1">data</span> <span class="pl-c1">=</span> [[<span class="pl-c1">418241</span>,<span class="pl-c1">442351</span>,<span class="pl-c1">2</span>,<span class="pl-c1">1905</span>,<span class="pl-c1">2</span>,<span class="pl-c1">2</span>,<span class="pl-c1">2</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">38</span>,<span class="pl-c1">7</span>,<span class="pl-c1">2</span> ],
[<span class="pl-c1">424993</span>,<span class="pl-c1">432898</span>,<span class="pl-c1">2</span>,<span class="pl-c1">1615</span>,<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">2</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">50</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span> ],
[<span class="pl-c1">431159</span>,<span class="pl-c1">436397</span>,<span class="pl-c1">2</span>,<span class="pl-c1">1645</span>,<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">26</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span> ],
[<span class="pl-c1">431159</span>,<span class="pl-c1">436397</span>,<span class="pl-c1">2</span>,<span class="pl-c1">1645</span>,<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">2</span>,<span class="pl-c1">22</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span> ],
[<span class="pl-c1">439313</span>,<span class="pl-c1">432376</span>,<span class="pl-c1">2</span>,<span class="pl-c1">956</span>,<span class="pl-c1">2</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">57</span>,<span class="pl-c1">2</span>,<span class="pl-c1">1</span> ],
[<span class="pl-c1">426994</span>,<span class="pl-c1">439957</span>,<span class="pl-c1">2</span>,<span class="pl-c1">1115</span>,<span class="pl-c1">2</span>,<span class="pl-c1">2</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">59</span>,<span class="pl-c1">2</span>,<span class="pl-c1">2</span> ],
[<span class="pl-c1">427813</span>,<span class="pl-c1">431257</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1352</span>,<span class="pl-c1">3</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">53</span>,<span class="pl-c1">1</span>,<span class="pl-c1">2</span> ],
[<span class="pl-c1">431496</span>,<span class="pl-c1">432727</span>,<span class="pl-c1">2</span>,<span class="pl-c1">2015</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>,<span class="pl-c1">2</span>,<span class="pl-c1">2</span>,<span class="pl-c1">22</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span> ],
[<span class="pl-c1">431880</span>,<span class="pl-c1">430498</span>,<span class="pl-c1">2</span>,<span class="pl-c1">1110</span>,<span class="pl-c1">3</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">2</span>,<span class="pl-c1">20</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>]]

<span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>(<span class="pl-s1">data</span>).<span class="pl-en">reshape</span>(<span class="pl-c1">-</span><span class="pl-c1">1</span>,<span class="pl-c1">13</span>)

<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">data</span>[:,<span class="pl-c1">12</span>]
<span class="pl-v">X</span> <span class="pl-c1">=</span> <span class="pl-s1">data</span>[:,<span class="pl-c1">0</span>:<span class="pl-c1">12</span>]

<span class="pl-s1">model</span> <span class="pl-c1">=</span> <span class="pl-v">GaussianNB</span>()
<span class="pl-s1">model</span>.<span class="pl-en">fit</span>(<span class="pl-v">X</span>, <span class="pl-s1">y</span>)

<span class="pl-v">X_test</span> <span class="pl-c1">=</span> [<span class="pl-s">'427750'</span>, <span class="pl-s">'426259'</span>, <span class="pl-s">'2'</span>, <span class="pl-s">'1610'</span>, <span class="pl-s">'2'</span>, <span class="pl-s">'1'</span>, <span class="pl-s">'2'</span>, <span class="pl-s">'1'</span>, <span class="pl-s">'4'</span>, <span class="pl-s">'1'</span>, <span class="pl-s">'47'</span>, <span class="pl-s">'2'</span>]
<span class="pl-v">X_test</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">reshape</span>(<span class="pl-v">X_test</span>, [<span class="pl-c1">1</span>, <span class="pl-c1">-</span><span class="pl-c1">1</span>])
<span class="pl-s1">y_pred</span> <span class="pl-c1">=</span> <span class="pl-s1">model</span>.<span class="pl-en">predict</span>(<span class="pl-v">X_test</span>)</pre></div>
<h4 dir="auto">Expected Results</h4>
<p dir="auto">Error should have been thrown as input in X_test is non numerical.</p>
<h4 dir="auto">Actual Results</h4>
<p dir="auto">A different error occured:</p>
<p dir="auto">File "/home/local/EZDI/vivek.k/Desktop/untitlsss.py", line 33, in <br>
y_pred = model.predict(X_test)</p>
<p dir="auto">File "/usr/local/lib/python2.7/dist-packages/sklearn/naive_bayes.py", line 66, in predict<br>
jll = self._joint_log_likelihood(X)</p>
<p dir="auto">File "/usr/local/lib/python2.7/dist-packages/sklearn/naive_bayes.py", line 433, in <em>joint_log_likelihood<br>
n_ij -= 0.5 * np.sum(((X - self.theta</em>[i, :]) ** 2) /</p>
<p dir="auto">TypeError: ufunc 'subtract' did not contain a loop with signature matching types dtype('S32') dtype('S32') dtype('S32')</p>
<p dir="auto">Currently, dtype='numeric' is defined as "dtype is preserved unless array.dtype is object". This seems overly lenient and strange behaviour, as in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="242363947" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/9342" data-hovercard-type="pull_request" data-hovercard-url="/scikit-learn/scikit-learn/pull/9342/hovercard" href="https://github.com/scikit-learn/scikit-learn/pull/9342">#9342</a> where <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/qinhanmin2014/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/qinhanmin2014">@qinhanmin2014</a> shows that <code class="notranslate">check_array(['a', 'b', 'c'], dtype='numeric')</code> works without error and produces an array of strings! This behaviour is not tested and it's hard to believe that it is useful and intended. Perhaps we need a deprecation cycle, but I think dtype='numeric' should raise an error, or attempt to coerce, if the data does not actually have a numeric, real-valued dtype.</p>