lib/rumale/ensemble/random_forest_classifier.rb
# Predict class labels for samples.
#
# @param x [Numo::DFloat] (shape: [n_samples, n_features]) The samples to predict the labels.
# @return [Numo::Int32] (shape: [n_samples]) Predicted class label per sample.
Predict class labels for samples.
Predict class labels for samples .
def predict(x)
        x = check_convert_sample_array(x)
        n_samples = x.shape[0]
        n_estimators = @estimators.size
        predicted = if enable_parallel?
                      predict_set = parallel_map(n_estimators) { |n| @estimators[n].predict(x).to_a }.transpose
                      parallel_map(n_samples) { |n| predict_set[n].group_by { |v| v }.max_by { |_k, v| v.size }.first }
                    else
                      predict_set = @estimators.map { |tree| tree.predict(x).to_a }.transpose
                      Array.new(n_samples) { |n| predict_set[n].group_by { |v| v }.max_by { |_k, v| v.size }.first }
                    end
        Numo::Int32.asarray(predicted)
      end
def predict ( x ) x = check_convert_sample_array ( x ) n_samples = x . shape [ 0 ] n_estimators = @estimators . size predicted = if enable_parallel? predict_set = parallel_map ( n_estimators ) { | n | @estimators [ n ] . predict ( x ) . to_a } . transpose parallel_map ( n_samples ) { | n | predict_set [ n ] . group_by { | v | v } . max_by { | _k , v | v . size } . first } else predict_set = @estimators . map { | tree | tree . predict ( x ) . to_a } . transpose Array . new ( n_samples ) { | n | predict_set [ n ] . group_by { | v | v } . max_by { | _k , v | v . size } . first } end Numo :: Int32 . asarray ( predicted ) end
Predict class labels for samples.
Predict class labels for samples .
[n_samples]) Predicted class label per sample.
[ n_samples ] ) Predicted class label per sample .
Numo::Int32
x
[n_samples, n_features]) The samples to predict the labels.
[ n_samples n_features ] ) The samples to predict the labels .