lib/rumale/kernel_machine/kernel_svc.rb
# Fit the model with given training data.
#
# @param x [Numo::DFloat] (shape: [n_training_samples, n_training_samples])
#   The kernel matrix of the training data to be used for fitting the model.
# @param y [Numo::Int32] (shape: [n_training_samples]) The labels to be used for fitting the model.
# @return [KernelSVC] 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)
        @classes = Numo::Int32[*y.to_a.uniq.sort]
        n_classes = @classes.size
        n_features = x.shape[1]
        if n_classes > 2
          @weight_vec = Numo::DFloat.zeros(n_classes, n_features)
          @prob_param = Numo::DFloat.zeros(n_classes, 2)
          models = if enable_parallel?
                     parallel_map(n_classes) do |n|
                       bin_y = Numo::Int32.cast(y.eq(@classes[n])) * 2 - 1
                       partial_fit(x, bin_y)
                     end
                   else
                     Array.new(n_classes) do |n|
                       bin_y = Numo::Int32.cast(y.eq(@classes[n])) * 2 - 1
                       partial_fit(x, bin_y)
                     end
                   end
          models.each_with_index { |model, n| @weight_vec[n, true], @prob_param[n, true] = model }
        else
          negative_label = y.to_a.uniq.min
          bin_y = Numo::Int32.cast(y.ne(negative_label)) * 2 - 1
          @weight_vec, @prob_param = partial_fit(x, bin_y)
        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 ) @classes = Numo :: Int32 [ * y . to_a . uniq . sort ] n_classes = @classes . size n_features = x . shape [ 1 ] if n_classes > 2 @weight_vec = Numo :: DFloat . zeros ( n_classes , n_features ) @prob_param = Numo :: DFloat . zeros ( n_classes , 2 ) models = if enable_parallel? parallel_map ( n_classes ) do | n | bin_y = Numo :: Int32 . cast ( y . eq ( @classes [ n ] ) ) * 2 - 1 partial_fit ( x , bin_y ) end else Array . new ( n_classes ) do | n | bin_y = Numo :: Int32 . cast ( y . eq ( @classes [ n ] ) ) * 2 - 1 partial_fit ( x , bin_y ) end end models . each_with_index { | model , n | @weight_vec [ n , true ] , @prob_param [ n , true ] = model } else negative_label = y . to_a . uniq . min bin_y = Numo :: Int32 . cast ( y . ne ( negative_label ) ) * 2 - 1 @weight_vec , @prob_param = partial_fit ( x , bin_y ) end self end
Fit the model with given training data.
Fit the model with given training data .
# :nocov: # :nocov:
The learned classifier itself.
The learned classifier itself .
KernelSVC
x
[n_training_samples, n_training_samples]) The kernel matrix of the training data to be used for fitting the model.
[ n_training_samples n_training_samples ] ) The kernel matrix of the training data to be used for fitting the model .
y
[n_training_samples]) The labels to be used for fitting the model.
[ n_training_samples ] ) The labels to be used for fitting the model .