forked from h2oai/h2o-3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/rel-3.44.0'
- Loading branch information
Showing
16 changed files
with
186 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
h2o-py/tests/testdir_algos/xgboost/pyunit_xgboost_custom_metric.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import sys | ||
|
||
sys.path.insert(1, "../../../") | ||
import h2o | ||
from tests import pyunit_utils | ||
from tests.pyunit_utils import CustomMaeFunc, CustomRmseFunc, \ | ||
assert_correct_custom_metric, regression_model, multinomial_model, binomial_model | ||
from h2o.estimators import H2OXGBoostEstimator | ||
from h2o.exceptions import H2OResponseError | ||
|
||
|
||
# Custom model metrics fixture | ||
def custom_mae_mm(): | ||
return h2o.upload_custom_metric(CustomMaeFunc, func_name="mae-custom", func_file="mm_mae.py") | ||
|
||
|
||
def custom_rmse_mm(): | ||
return h2o.upload_custom_metric(CustomRmseFunc, func_name="rmse-custom", func_file="mm_rmse.py") | ||
|
||
|
||
# Test that the custom model metric is computed | ||
# and compare them with implicit custom metric | ||
def test_custom_metric_computation_regression(): | ||
(model, f_test) = regression_model(H2OXGBoostEstimator, custom_mae_mm()) | ||
print(model) | ||
assert_correct_custom_metric(model, f_test, "mae", "Regression on prostate") | ||
|
||
|
||
def test_custom_metric_computation_binomial(): | ||
(model, f_test) = binomial_model(H2OXGBoostEstimator, custom_rmse_mm()) | ||
print(model) | ||
assert_correct_custom_metric(model, f_test, "rmse", "Binomial on prostate") | ||
|
||
|
||
def test_custom_metric_computation_together_with_eval_metric(): | ||
params = {"eval_metric": "[email protected]"} | ||
try: | ||
binomial_model(H2OXGBoostEstimator, custom_rmse_mm(), params) | ||
raise "Should fail" | ||
except H2OResponseError as e: | ||
assert "Custom metric is not supported together with eval_metric parameter" in str(e) | ||
|
||
|
||
def test_custom_metric_computation_multinomial(): | ||
(model, f_test) = multinomial_model(H2OXGBoostEstimator, custom_rmse_mm()) | ||
print(model) | ||
assert_correct_custom_metric(model, f_test, "rmse", "Multinomial on iris") | ||
|
||
|
||
# Tests to invoke in this suite | ||
__TESTS__ = [ | ||
test_custom_metric_computation_binomial, | ||
test_custom_metric_computation_regression, | ||
test_custom_metric_computation_multinomial, | ||
test_custom_metric_computation_together_with_eval_metric | ||
] | ||
|
||
if __name__ == "__main__": | ||
for func in __TESTS__: | ||
pyunit_utils.standalone_test(func) | ||
else: | ||
for func in __TESTS__: | ||
func() |
Oops, something went wrong.