Skip to content

Commit

Permalink
GH-15809: implement AIC and Loglikelihood calculations for ModelMetri…
Browse files Browse the repository at this point in the history
…csBinomial
  • Loading branch information
syzonyuliia-h2o committed Jan 17, 2024
1 parent 0ff937d commit 566eb00
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions h2o-core/src/main/java/hex/ModelMetricsBinomial.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ public static class MetricBuilderBinomial<T extends MetricBuilderBinomial<T>> ex
// Compute log loss
_logloss += w * MathUtils.logloss(err);
}

if(m.getClass().toString().contains("Generic")) {
_loglikelihood += m.likelihood(w, yact[0], ds);
System.out.println("_logloss: " + _logloss);
System.out.println("_loglikelihood: " + _loglikelihood);
}

_count++;
_wcount += w;
assert !Double.isNaN(_sumsqe);
Expand All @@ -216,6 +223,7 @@ public static class MetricBuilderBinomial<T extends MetricBuilderBinomial<T>> ex
@Override public void reduce( T mb ) {
super.reduce(mb); // sumseq, count
_logloss += mb._logloss;
_loglikelihood += mb._loglikelihood;
_auc.reduce(mb._auc);
}

Expand Down Expand Up @@ -274,6 +282,10 @@ private ModelMetrics makeModelMetrics(Model m, Frame f, GainsLift gl) {
sigma = weightedSigma();
mse = _sumsqe / _wcount;
logloss = _logloss / _wcount;
if(m.getClass().toString().contains("Generic")) {
loglikelihood = -1 * _loglikelihood ; // get likelihood from negative loglikelihood
aic = m.aic(loglikelihood);
}
auc = new AUC2(_auc);
} else {
auc = new AUC2();
Expand Down

0 comments on commit 566eb00

Please sign in to comment.