lib/rumale/naive_bayes/gaussian_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
        log_likelihoods = Array.new(n_classes) do |l|
          Math.log(@class_priors[l]) - 0.5 * (
            Numo::NMath.log(2.0 * Math::PI * @variances[l, true]) +
            ((x - @means[l, true])**2 / @variances[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 log_likelihoods = Array . new ( n_classes ) do | l | Math . log ( @class_priors [ l ] ) - 0.5 * ( Numo :: NMath . log ( 2.0 * Math :: PI * @variances [ l , true ] ) + ( ( x - @means [ l , true ] ) ** 2 / @variances [ 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 .