-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-7118 - add score_each_iteration, score_tree_interval, disable_trai…
…ning_metrics to Python, R and documentation (#6038) * eif scoring history - add score_each_iteration and score_tree_interval to API * eif scoring history - test python and R api * eif scoring history - add score_each_iteration and score_tree_interval to the documentation * add posibility to disable training metrics API * eif - test scoring with large data in python
- Loading branch information
Showing
9 changed files
with
183 additions
and
4 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
31 changes: 31 additions & 0 deletions
31
h2o-py/tests/testdir_algos/isoforextended/pyunit_isoforextended_metrics_large.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,31 @@ | ||
from __future__ import print_function | ||
import sys, os | ||
sys.path.insert(1, os.path.join("..","..","..")) | ||
import h2o | ||
from tests import pyunit_utils, assert_equals | ||
from h2o.estimators.extended_isolation_forest import H2OExtendedIsolationForestEstimator | ||
|
||
|
||
def extended_isolation_forest_metrics_large(): | ||
print("Extended Isolation Forest Anomaly Metrics Test On Large Data") | ||
|
||
train = h2o.import_file(pyunit_utils.locate("bigdata/laptop/creditcardfraud/creditcardfraud.csv")) | ||
|
||
eif_model = H2OExtendedIsolationForestEstimator(ntrees=100, seed=0xBEEF, sample_size=256, extension_level=1, disable_training_metrics=False) | ||
eif_model.train(training_frame=train) | ||
metrics_by_python = eif_model.predict(train).mean() | ||
average_mean_length = metrics_by_python[0, 1] | ||
average_anomaly_score = metrics_by_python[0, 0] | ||
|
||
print(metrics_by_python) | ||
print(eif_model) | ||
|
||
perf = eif_model.model_performance() | ||
assert_equals(perf.mean_score(), average_mean_length, "Mean score metric is not correct", 1e-3) | ||
assert_equals(perf.mean_normalized_score(), average_anomaly_score, "Anomaly score metric is not correct", 1e-3) | ||
|
||
|
||
if __name__ == "__main__": | ||
pyunit_utils.standalone_test(extended_isolation_forest_metrics_large) | ||
else: | ||
extended_isolation_forest_metrics_large() |
35 changes: 35 additions & 0 deletions
35
h2o-py/tests/testdir_algos/isoforextended/pyunit_isoforextended_scoring_history.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,35 @@ | ||
from __future__ import print_function | ||
import sys, os | ||
sys.path.insert(1, os.path.join("..","..","..")) | ||
import h2o | ||
from tests import pyunit_utils, assert_equals | ||
from h2o.estimators.extended_isolation_forest import H2OExtendedIsolationForestEstimator | ||
|
||
|
||
def extended_isolation_forest_scoring_history(): | ||
print("Extended Isolation Forest Scoring History Test") | ||
|
||
train = h2o.import_file(pyunit_utils.locate("smalldata/anomaly/single_blob.csv")) | ||
|
||
eif_model = H2OExtendedIsolationForestEstimator(ntrees=10, seed=0xBEEF, sample_size=255, extension_level=1) | ||
eif_model.train(training_frame=train) | ||
print(eif_model.scoring_history()) | ||
assert_equals(None, eif_model.scoring_history(), "No scoring history by default") | ||
|
||
eif_model = H2OExtendedIsolationForestEstimator(ntrees=10, seed=0xBEEF, sample_size=255, extension_level=1, | ||
score_each_iteration=True, disable_training_metrics=False) | ||
eif_model.train(training_frame=train) | ||
print(eif_model.scoring_history()) | ||
assert_equals(11, len(eif_model.scoring_history()), "There should be one empty row and one row for each tree") | ||
|
||
eif_model = H2OExtendedIsolationForestEstimator(ntrees=10, seed=0xBEEF, sample_size=255, extension_level=1, | ||
score_tree_interval=3, disable_training_metrics=False) | ||
eif_model.train(training_frame=train) | ||
print(eif_model.scoring_history()) | ||
assert_equals(5, len(eif_model.scoring_history()), "There should be one empty row and one row for each interval") | ||
|
||
|
||
if __name__ == "__main__": | ||
pyunit_utils.standalone_test(extended_isolation_forest_scoring_history) | ||
else: | ||
extended_isolation_forest_scoring_history() |
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
20 changes: 20 additions & 0 deletions
20
h2o-r/tests/testdir_algos/isoforextended/runit_isoforextended_scoring_history.R
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,20 @@ | ||
setwd(normalizePath(dirname(R.utils::commandArgs(asValues=TRUE)$"f"))) | ||
source("../../../scripts/h2o-r-test-setup.R") | ||
|
||
|
||
|
||
test.ExtendedIsolationForest.scoring_history <- function() { | ||
single_blob.hex <- | ||
h2o.importFile(path = locate("smalldata/anomaly/single_blob.csv"), | ||
destination_frame = "single_blob.hex") | ||
|
||
exisofor.model <- h2o.extendedIsolationForest(training_frame = single_blob.hex, score_each_iteration=TRUE, ntrees=10, disable_training_metrics=FALSE) | ||
print(exisofor.model) | ||
expect_equal(nrow(h2o.scoreHistory(exisofor.model)), 11) | ||
|
||
exisofor.model <- h2o.extendedIsolationForest(training_frame = single_blob.hex, score_tree_interval=3, ntrees=10, disable_training_metrics=FALSE) | ||
print(exisofor.model) | ||
expect_equal(nrow(h2o.scoreHistory(exisofor.model)), 5) | ||
} | ||
|
||
doTest("ExtendedIsolationForest: Smoke Test For Scoring History", test.ExtendedIsolationForest.scoring_history) |