Commit 6febaa4
Fix CategoricalNB predict's feature-count check and min_categories option
check_dim compared x's feature count against
Nx.axis_size(model.feature_count, 1), but feature_count here is
{num_features, num_classes, num_categories} (unlike the 2D
{num_classes, num_features} in the other NaiveBayes modules this was
copied from), so axis 1 is num_classes. Every predict/*_probability
call rejected correctly-shaped input whenever num_features didn't
happen to equal num_classes, and would silently accept wrongly-shaped
input in the reverse case. Fixed to read axis 0.
Separately, fit's min_categories option was dead: Keyword.pop removed
:min_categories from opts and rebound it, so the very next read of
opts[:min_categories] (used to size the feature_count/
feature_log_probability tensors) always saw nil and silently fell back
to inferring the category count from the training data alone. Kept a
flag captured before the pop and branched on it instead, matching
sklearn.naive_bayes.CategoricalNB's min_categories semantics (a literal
per-feature category count, not a max index) - verified shapes match
sklearn exactly for both list and tensor min_categories inputs.1 parent 4deb282 commit 6febaa4
1 file changed
Lines changed: 8 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
279 | 280 | | |
280 | 281 | | |
281 | 282 | | |
| |||
360 | 361 | | |
361 | 362 | | |
362 | 363 | | |
363 | | - | |
| 364 | + | |
364 | 365 | | |
365 | 366 | | |
366 | 367 | | |
| |||
401 | 402 | | |
402 | 403 | | |
403 | 404 | | |
404 | | - | |
| 405 | + | |
405 | 406 | | |
406 | 407 | | |
407 | 408 | | |
| |||
453 | 454 | | |
454 | 455 | | |
455 | 456 | | |
456 | | - | |
| 457 | + | |
457 | 458 | | |
458 | 459 | | |
459 | 460 | | |
| |||
0 commit comments