Skip to content

Commit

Permalink
GH-15719: fix parameters checks and AIC warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
syzonyuliia-h2o committed Sep 18, 2023
1 parent 3e70494 commit f5fec9f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
15 changes: 5 additions & 10 deletions h2o-py/h2o/model/model_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,13 +544,13 @@ def negative_log_likelihood(self):
:return: the negative likelihood function value
"""
if self.parms['calc_like']:
if self.parms['calc_like']['actual_value']:
warning_message = "This is the simplified negative log likelihood function used during training for " \
"speedup. To see the correct value call model.model_performance().loglikelihood()"
"speedup. To see the correct value call model.model_performance().loglikelihood()."
else:
warning_message = "This is the simplified negative log likelihood function used during training for " \
"speedup. To see the correct value, set calc_like=True, retrain the model and call " \
"model.model_performance().loglikelihood()"
"model.model_performance().loglikelihood()."
warnings.warn(warning_message, UserWarning, stacklevel=2)
return self._extract_scoring_history("negative_log_likelihood")

Expand Down Expand Up @@ -1048,16 +1048,11 @@ def aic(self, train=False, valid=False, xval=False):
:returns: The AIC.
"""
if self.parms['calc_like']:
warning_message = "This is the AIC function using the simplified negative log likelihood used during " \
"training for speedup. To see the correct value call " \
"model.model_performance().aic() again."
else:

if not self.parms['calc_like']['actual_value']:
warning_message = "This is the AIC function using the simplified negative log likelihood used during " \
"training for speedup. To see the correct value, set calc_like=True, " \
"retrain the model and call model.model_performance().aic() again."
warnings.warn(warning_message, UserWarning, stacklevel=2)
warnings.warn(warning_message, UserWarning, stacklevel=2)
tm = ModelBase._get_metrics(self, train, valid, xval)
m = {}
for k, v in tm.items(): m[k] = None if v is None else v.aic()
Expand Down
7 changes: 2 additions & 5 deletions h2o-r/h2o-package/R/models.R
Original file line number Diff line number Diff line change
Expand Up @@ -2009,15 +2009,12 @@ h2o.mean_per_class_error <- function(object, train=FALSE, valid=FALSE, xval=FALS
h2o.aic <- function(object, train=FALSE, valid=FALSE, xval=FALSE) {
if( is(object, "H2OModelMetrics") ) return( object@metrics$AIC )
if( is(object, "H2OModel") ) {
if (model@allparameters$calc_like) {
warning_message <- paste0("This is the AIC function using the simplified negative log likelihood used during ",
"training for speedup. To see the correct value call h2o.aic(model).")
} else {
if (!object@allparameters$calc_like) {
warning_message <- paste0("This is the AIC function using the simplified negative log likelihood used during ",
"training for speedup. To see the correct value, set calc_like=True, ",
"retrain and call h2o.aic(model).")
warning(warning_message)
}
warning(warning_message)
model.parts <- .model.parts(object)
if ( !train && !valid && !xval ) {
metric <- model.parts$tm@metrics$AIC
Expand Down

0 comments on commit f5fec9f

Please sign in to comment.