yobx.sklearn.naive_bayes.categorical_nb#

yobx.sklearn.naive_bayes.categorical_nb.sklearn_categorical_nb(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: CategoricalNB, X: str, name: str = 'categorical_nb') Tuple[str, str][source]#

Converts a sklearn.naive_bayes.CategoricalNB into ONNX.

The joint log-likelihood for class c is:

jll[n, c] = class_log_prior_[c]
            + Σ_f  feature_log_prob_[f][c, X[n, f]]

For each feature f, feature_log_prob_[f] has shape (C, n_categories[f]). The contribution is looked up via a Gather on the transposed table feature_log_prob_[f].T (shape n_categories[f] × C) using the integer feature column X[:, f] as indices.

probabilities ← Softmax(jll, axis=1) label ← classes_[ArgMax(jll, axis=1)]

Parameters:
  • g – the graph builder to add nodes to

  • sts – shapes defined by scikit-learn

  • outputs – desired names (label, probabilities)

  • estimator – a fitted CategoricalNB

  • X – input tensor name (integer category indices)

  • name – prefix for added node names

Returns:

tuple (label_result_name, proba_result_name)