lib/rumale/kernel_machine/kernel_ridge_classifier.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 [KernelRidgeClassifier] 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)
        raise ArgumentError, 'Expect the kernel matrix of training data to be square.' unless x.shape[0] == x.shape[1]
        raise 'KernelRidgeClassifier#fit requires Numo::Linalg but that is not loaded.' unless enable_linalg?
        @encoder = Rumale::Preprocessing::LabelBinarizer.new
        y_encoded = Numo::DFloat.cast(@encoder.fit_transform(y)) * 2 - 1
        @classes = Numo::NArray[*@encoder.classes]
        n_samples = x.shape[0]
        reg_kernel_mat = x + Numo::DFloat.eye(n_samples) * @params[:reg_param]
        @weight_vec = Numo::Linalg.solve(reg_kernel_mat, y_encoded, driver: 'sym')
        self
      end
def fit ( x , y ) x = check_convert_sample_array ( x ) y = check_convert_label_array ( y ) check_sample_label_size ( x , y ) raise ArgumentError , 'Expect the kernel matrix of training data to be square.' unless x . shape [ 0 ] == x . shape [ 1 ] raise 'KernelRidgeClassifier#fit requires Numo::Linalg but that is not loaded.' unless enable_linalg? @encoder = Rumale :: Preprocessing :: LabelBinarizer . new y_encoded = Numo :: DFloat . cast ( @encoder . fit_transform ( y ) ) * 2 - 1 @classes = Numo :: NArray [ * @encoder . classes ] n_samples = x . shape [ 0 ] reg_kernel_mat = x + Numo :: DFloat . eye ( n_samples ) * @params [ :reg_param ] @weight_vec = Numo :: Linalg . solve ( reg_kernel_mat , y_encoded , driver : 'sym' ) self end
Fit the model with given training data.
Fit the model with given training data .
The learned classifier itself.
The learned classifier itself .
KernelRidgeClassifier
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 .