You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: kernel_ridge.rb
    path of file: ./repos/rumale/rumale-kernel_machine/lib/rumale/kernel_machine
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

require 'rumale/base/estimator'
require 'rumale/base/regressor'
require 'rumale/validation'

module Rumale
  module KernelMachine
    # KernelRidge is a class that implements kernel ridge regression.
    #
    # @example
    #   require 'numo/linalg/autoloader'
    #   require 'rumale/pairwise_metric'
    #   require 'rumale/kernel_machine/kernel_ridge'
    #
    #   kernel_mat_train = Rumale::PairwiseMetric::rbf_kernel(training_samples)
    #   kridge = Rumale::KernelMachine::KernelRidge.new(reg_param: 1.0)
    #   kridge.fit(kernel_mat_train, traininig_values
    
      def fit(x, y)
        x = ::Rumale::Validation.check_convert_sample_array(x)
        y = ::Rumale::Validation.check_convert_target_value_array(y)
        ::Rumale::Validation.check_sample_size(x, y)
        raise ArgumentError, 'Expect the kernel matrix of training data to be square.' unless x.shape[0] == x.shape[1]
        raise 'KernelRidge#fit requires Numo::Linalg but that is not loaded.' unless enable_linalg?(warning: false)

        n_samples = x.shape[0]

        if @params[:reg_param].is_a?(Float)
          reg_kernel_mat = x + Numo::DFloat.eye(n_samples) * @params[:reg_param]
          @weight_vec = Numo::Linalg.solve(reg_kernel_mat, y, driver: 'sym')
        else
          n_outputs = y.shape[1]
          @weight_vec = Numo::DFloat.zeros(n_samples, n_outputs)
          n_outputs.times do |n|
            reg_kernel_mat = x + Numo::DFloat.eye(n_samples) * @params[:reg_param][n]
            @weight_vec[true, n] = Numo::Linalg.solve(reg_kernel_mat, y[true, n], driver: 'sym')
          end
        end