lib/rumale/naive_bayes/bernoulli_nb.rb
# Fit the model with given training data.
#
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The training data to be used for fitting the model.
# @param y [Numo::Int32] (shape: [n_samples]) The categorical variables (e.g. labels)
#   to be used for fitting the model.
# @return [BernoulliNB] The learned classifier itself.
Fit the model with given training data.
Fit the model with given training data .
def fit(x, y)
        x = check_convert_sample_array(x)
        y = check_convert_label_array(y)
        check_sample_label_size(x, y)
        n_samples, = x.shape
        bin_x = Numo::DFloat[*x.gt(@params[:bin_threshold])]
        @classes = Numo::Int32[*y.to_a.uniq.sort]
        n_samples_each_class = Numo::DFloat[*@classes.to_a.map { |l| y.eq(l).count.to_f }]
        @class_priors = n_samples_each_class / n_samples
        count_features = Numo::DFloat[*@classes.to_a.map { |l| bin_x[y.eq(l).where, true].sum(0) }]
        count_features += @params[:smoothing_param]
        n_samples_each_class += 2.0 * @params[:smoothing_param]
        n_classes = @classes.size
        @feature_probs = count_features / n_samples_each_class.reshape(n_classes, 1)
        self
      end
def fit ( x , y ) x = check_convert_sample_array ( x ) y = check_convert_label_array ( y ) check_sample_label_size ( x , y ) n_samples , = x . shape bin_x = Numo :: DFloat [ * x . gt ( @params [ :bin_threshold ] ) ] @classes = Numo :: Int32 [ * y . to_a . uniq . sort ] n_samples_each_class = Numo :: DFloat [ * @classes . to_a . map { | l | y . eq ( l ) . count . to_f } ] @class_priors = n_samples_each_class / n_samples count_features = Numo :: DFloat [ * @classes . to_a . map { | l | bin_x [ y . eq ( l ) . where , true ] . sum ( 0 ) } ] count_features += @params [ :smoothing_param ] n_samples_each_class += 2.0 * @params [ :smoothing_param ] n_classes = @classes . size @feature_probs = count_features / n_samples_each_class . reshape ( n_classes , 1 ) self end
Fit the model with given training data.
Fit the model with given training data .
The learned classifier itself.
The learned classifier itself .
BernoulliNB
x
[n_samples, n_features]) The training data to be used for fitting the model.
[ n_samples n_features ] ) The training data to be used for fitting the model .
y
[n_samples]) The categorical variables  to be used for fitting the model.
[ n_samples ] ) The categorical variables to be used for fitting the model .