lib/rumale/ensemble/gradient_boosting_classifier.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 labels to be used for fitting the model.
# @return [GradientBoostingClassifier] 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_features = x.shape[1]
        @params[:max_features] = n_features if @params[:max_features].nil?
        @params[:max_features] = [[1, @params[:max_features]].max, n_features].min
        @classes = Numo::Int32[*y.to_a.uniq.sort]
        n_classes = @classes.size
        if n_classes > 2
          @base_predictions = multiclass_base_predictions(y)
          @estimators = multiclass_estimators(x, y)
        else
          negative_label = y.to_a.uniq.min
          bin_y = Numo::DFloat.cast(y.ne(negative_label)) * 2 - 1
          y_mean = bin_y.mean
          @base_predictions = 0.5 * Numo::NMath.log((1.0 + y_mean) / (1.0 - y_mean))
          @estimators = partial_fit(x, bin_y, @base_predictions)
        end
        @feature_importances = if n_classes > 2
                                 multiclass_feature_importances
                               else
                                 @estimators.map(&:feature_importances).reduce(&:+)
                               end
        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_features = x . shape [ 1 ] @params [ :max_features ] = n_features if @params [ :max_features ] . nil? @params [ :max_features ] = [ [ 1 , @params [ :max_features ] ] . max , n_features ] . min @classes = Numo :: Int32 [ * y . to_a . uniq . sort ] n_classes = @classes . size if n_classes > 2 @base_predictions = multiclass_base_predictions ( y ) @estimators = multiclass_estimators ( x , y ) else negative_label = y . to_a . uniq . min bin_y = Numo :: DFloat . cast ( y . ne ( negative_label ) ) * 2 - 1 y_mean = bin_y . mean @base_predictions = 0.5 * Numo :: NMath . log ( ( 1.0 + y_mean ) / ( 1.0 - y_mean ) ) @estimators = partial_fit ( x , bin_y , @base_predictions ) end @feature_importances = if n_classes > 2 multiclass_feature_importances else @estimators . map ( & :feature_importances ) . reduce ( & :+ ) end self end
Fit the model with given training data.
Fit the model with given training data .
# initialize some variables. # train estimator. # calculate feature importances.
The learned classifier itself.
The learned classifier itself .
GradientBoostingClassifier
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 labels to be used for fitting the model.
[ n_samples ] ) The labels to be used for fitting the model .