lib/rumale/naive_bayes/bernoulli_nb.rb
# Calculate confidence scores for samples.
#
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to compute the scores.
# @return [Numo::DFloat] (shape: [n_samples, n_classes]) Confidence scores per sample for each class.
Calculate confidence scores for samples.
Calculate confidence scores for samples .
def decision_function(x)
        x = check_convert_sample_array(x)
        n_classes = @classes.size
        bin_x = Numo::DFloat[*x.gt(@params[:bin_threshold])]
        not_bin_x = Numo::DFloat[*x.le(@params[:bin_threshold])]
        log_likelihoods = Array.new(n_classes) do |l|
          Math.log(@class_priors[l]) + (
            (Numo::DFloat[*bin_x] * Numo::NMath.log(@feature_probs[l, true])).sum(1)
            (Numo::DFloat[*not_bin_x] * Numo::NMath.log(1.0 - @feature_probs[l, true])).sum(1))
        end
        Numo::DFloat[*log_likelihoods].transpose.dup
      end
def decision_function ( x ) x = check_convert_sample_array ( x ) n_classes = @classes . size bin_x = Numo :: DFloat [ * x . gt ( @params [ :bin_threshold ] ) ] not_bin_x = Numo :: DFloat [ * x . le ( @params [ :bin_threshold ] ) ] log_likelihoods = Array . new ( n_classes ) do | l | Math . log ( @class_priors [ l ] ) + ( ( Numo :: DFloat [ * bin_x ] * Numo :: NMath . log ( @feature_probs [ l , true ] ) ) . sum ( 1 ) ( Numo :: DFloat [ * not_bin_x ] * Numo :: NMath . log ( 1.0 - @feature_probs [ l , true ] ) ) . sum ( 1 ) ) end Numo :: DFloat [ * log_likelihoods ] . transpose . dup end
Calculate confidence scores for samples.
Calculate confidence scores for samples .
[n_samples, n_classes]) Confidence scores per sample for each class.
[ n_samples n_classes ] ) Confidence scores per sample for each class .
Numo::DFloat
x
[n_samples, n_features]) The samples to compute the scores.
[ n_samples n_features ] ) The samples to compute the scores .