Sha256: c1551e4c38a0a5db499dce27333a64f3a3c0f3297362e6af1ca217c0f848f4c7

Contents?: true

Size: 974 Bytes

Versions: 2

Compression:

Stored size: 974 Bytes

Contents

module XGBoost
  class EvaluationMonitor < TrainingCallback
    def initialize(period:, show_stdv: false)
      @show_stdv = show_stdv
      @period = period
    end

    def after_iteration(model, epoch, evals_log)
      if evals_log.empty?
        return false
      end

      msg = "[#{epoch}]"
      evals_log.each do |data, metric|
        metric.each do |metric_name, log|
          stdv = nil
          if log[-1].is_a?(Array)
            score = log[-1][0]
            stdv = log[-1][1]
          else
            score = log[-1]
          end
          msg += fmt_metric(data, metric_name, score, stdv)
        end
      end
      msg += "\n"

      if epoch % @period == 0
        puts msg
      end
      false
    end

    private

    def fmt_metric(data, metric, score, std)
      if !std.nil? && @show_stdv
        "\t%s:%.5f+%.5f" % [data + "-" + metric, score, std]
      else
        "\t%s:%.5f" % [data + "-" + metric, score]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
honzasterba_xgb-0.9.0 lib/xgboost/evaluation_monitor.rb
xgb-0.9.0 lib/xgboost/evaluation_monitor.rb