Sha256: 98a3b1ed4202b3f0c223b9f44696b93af29dd71d1d2a8193196ff49c2b4f31a8

Contents?: true

Size: 672 Bytes

Versions: 3

Compression:

Stored size: 672 Bytes

Contents

module LightGBM
  module Utils
    private

    def check_result(err)
      raise LightGBM::Error, FFI.LGBM_GetLastError if err != 0
    end

    # remove spaces in keys and values to prevent injection
    def params_str(params)
      params.map { |k, v| [check_param(k.to_s), check_param(Array(v).join(",").to_s)].join("=") }.join(" ")
    end

    def check_param(v)
      raise ArgumentError, "Invalid parameter" if /[[:space:]]/.match(v)
      v
    end

    # change default verbosity
    def set_verbosity(params)
      params_keys = params.keys.map(&:to_s)
      unless params_keys.include?("verbosity")
        params["verbosity"] = -1
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lightgbm-0.1.4 lib/lightgbm/utils.rb
lightgbm-0.1.3 lib/lightgbm/utils.rb
lightgbm-0.1.2 lib/lightgbm/utils.rb