Skip to content

Commit

Permalink
GH-15809: assign NaN instead of 0 as placeholder value for Loglikelihood
Browse files Browse the repository at this point in the history
  • Loading branch information
syzonyuliia-h2o authored and wendycwong committed Feb 5, 2024
1 parent 211ba61 commit c08e2f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions h2o-algos/src/main/java/hex/generic/GenericModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private Iced getParamByName(String name) {
public double aic(double likelihood) {
// calculate negative loglikelihood specifically for GLM
if (!_algoName.equals("glm")) {
return 0;
return Double.NaN;
} else {
long betasCount = Arrays.stream(((GlmMojoModelBase) this.genModel()).getBeta()).filter(b -> b != 0).count();
return -2 * likelihood + 2 * betasCount;
Expand All @@ -174,8 +174,10 @@ public double aic(double likelihood) {

@Override
public double likelihood(double w, double y, double[] f) {
// calculate negative loglikelihood specifically for GLM
if (w == 0 || !_algoName.equals("glm")) {
// calculate negative loglikelihood specifically for GLM
if(!_algoName.equals("glm")) {
return Double.NaN;
} else if (w == 0) {
return 0;
} else {
// time-consuming calculation for the final scoring for GLM model
Expand Down
4 changes: 2 additions & 2 deletions h2o-core/src/main/java/hex/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -1381,11 +1381,11 @@ public double deviance(double w, double y, double f) {
}

public double likelihood(double w, double y, double[] f) {
return 0.0; // place holder. This function is overridden in GLM.
return Double.NaN; // placeholder. This function is overridden in GLM and GenericModel.
}

public double aic(double likelihood) {
return 0.0; // place holder. This function is overridden in GLM.
return Double.NaN; // placeholder. This function is overridden in GenericModel.
}

public ScoringInfo[] scoring_history() { return scoringInfo; }
Expand Down

0 comments on commit c08e2f5

Please sign in to comment.