Module: Eps::Metrics

Defined in:
lib/eps/metrics.rb

Class Method Summary collapse

Class Method Details

.accuracy(y_true, y_pred) ⇒ Object


19
20
21
22
# File 'lib/eps/metrics.rb', line 19

def accuracy(y_true, y_pred)
  check_size(y_true, y_pred)
  y_true.zip(y_pred).count { |yt, yp| yt == yp } / y_true.size.to_f
end

.log_loss(y_true, y_pred, eps: 1e-15) ⇒ Object


25
26
27
28
29
# File 'lib/eps/metrics.rb', line 25

def log_loss(y_true, y_pred, eps: 1e-15)
  check_size(y_true, y_pred)
  p = y_pred.map { |yp| yp.clamp(eps, 1 - eps) }
  mean(y_true.zip(p).map { |yt, pi| yt == 1 ? -Math.log(pi) : -Math.log(1 - pi) })
end

.mae(y_true, y_pred) ⇒ Object


9
10
11
12
# File 'lib/eps/metrics.rb', line 9

def mae(y_true, y_pred)
  check_size(y_true, y_pred)
  mean(errors(y_true, y_pred).map { |v| v.abs })
end

.me(y_true, y_pred) ⇒ Object


14
15
16
17
# File 'lib/eps/metrics.rb', line 14

def me(y_true, y_pred)
  check_size(y_true, y_pred)
  mean(errors(y_true, y_pred))
end

.rmse(y_true, y_pred) ⇒ Object


4
5
6
7
# File 'lib/eps/metrics.rb', line 4

def rmse(y_true, y_pred)
  check_size(y_true, y_pred)
  Math.sqrt(mean(errors(y_true, y_pred).map { |v| v**2 }))
end