Sha256: 3e7435c365effcae81196c339367ffe308c81254ffa85c65c80acb398251d38c

Contents?: true

Size: 1.14 KB

Versions: 13

Compression:

Stored size: 1.14 KB

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

    # for categorical, NaN and negative value are the same
    def handle_missing(data)
      data.map! { |v| v.nil? ? Float::NAN : v }
    end

    def matrix?(data)
      defined?(Matrix) && data.is_a?(Matrix)
    end

    def daru?(data)
      defined?(Daru::DataFrame) && data.is_a?(Daru::DataFrame)
    end

    def numo?(data)
      defined?(Numo::NArray) && data.is_a?(Numo::NArray)
    end

    def rover?(data)
      defined?(Rover::DataFrame) && data.is_a?(Rover::DataFrame)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
lightgbm-0.3.3 lib/lightgbm/utils.rb
lightgbm-0.3.2 lib/lightgbm/utils.rb
lightgbm-0.3.1 lib/lightgbm/utils.rb
lightgbm-0.3.0 lib/lightgbm/utils.rb
lightgbm-0.2.7 lib/lightgbm/utils.rb
lightgbm-0.2.6 lib/lightgbm/utils.rb
lightgbm-0.2.5 lib/lightgbm/utils.rb
lightgbm-0.2.4 lib/lightgbm/utils.rb
lightgbm-0.2.3 lib/lightgbm/utils.rb
lightgbm-0.2.2 lib/lightgbm/utils.rb
lightgbm-0.2.1 lib/lightgbm/utils.rb
lightgbm-0.2.0 lib/lightgbm/utils.rb
lightgbm-0.1.9 lib/lightgbm/utils.rb