lib/rumale/naive_bayes/gaussian_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 [GaussianNB] 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
        @classes = Numo::Int32[*y.to_a.uniq.sort]
        @class_priors = Numo::DFloat[*@classes.to_a.map { |l| y.eq(l).count / n_samples.to_f }]
        @means = Numo::DFloat[*@classes.to_a.map { |l| x[y.eq(l).where, true].mean(0) }]
        @variances = Numo::DFloat[*@classes.to_a.map { |l| x[y.eq(l).where, true].var(0) }]
        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 @classes = Numo :: Int32 [ * y . to_a . uniq . sort ] @class_priors = Numo :: DFloat [ * @classes . to_a . map { | l | y . eq ( l ) . count / n_samples . to_f } ] @means = Numo :: DFloat [ * @classes . to_a . map { | l | x [ y . eq ( l ) . where , true ] . mean ( 0 ) } ] @variances = Numo :: DFloat [ * @classes . to_a . map { | l | x [ y . eq ( l ) . where , true ] . var ( 0 ) } ] self end
Fit the model with given training data.
Fit the model with given training data .
The learned classifier itself.
The learned classifier itself .
GaussianNB
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 .