Class: XGBoost::EvaluationMonitor

Inherits:
TrainingCallback show all
Defined in:
lib/xgboost/evaluation_monitor.rb

Instance Method Summary collapse

Methods inherited from TrainingCallback

#after_training, #before_iteration, #before_training

Constructor Details

#initialize(period:, show_stdv: false) ⇒ EvaluationMonitor

Returns a new instance of EvaluationMonitor.



3
4
5
6
# File 'lib/xgboost/evaluation_monitor.rb', line 3

def initialize(period:, show_stdv: false)
  @show_stdv = show_stdv
  @period = period
end

Instance Method Details

#after_iteration(model, epoch, evals_log) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/xgboost/evaluation_monitor.rb', line 8

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