<commit_before>from __future__ import print_function
import sys, os
sys.path.insert(1, os.path.join("..","..",".."))
import h2o
from tests import pyunit_utils
from h2o.estimators.extended_isolation_forest import H2OExtendedIsolationForestEstimator


def extended_isolation_forest():
    print("Extended Isolation Forest Smoke Test")

    train = h2o.import_file(pyunit_utils.locate("smalldata/anomaly/single_blob.csv"))

    eif_model = H2OExtendedIsolationForestEstimator(ntrees=7, seed=12, sample_size=5)
    eif_model.train(training_frame=train)

    print(eif_model)

if __name__ == "__main__":
    pyunit_utils.standalone_test(extended_isolation_forest)
else:
    extended_isolation_forest()<commit_msg>PUBDEV-7138 - Extended Isolation Forest smoke test improvement. Assert random prediction to specific value.<commit_after>from __future__ import print_function
import sys, os
sys.path.insert(1, os.path.join("..","..",".."))
import h2o
from tests import pyunit_utils
from h2o.estimators.extended_isolation_forest import H2OExtendedIsolationForestEstimator


def extended_isolation_forest():
    print("Extended Isolation Forest Smoke Test")

    train = h2o.import_file(pyunit_utils.locate("smalldata/anomaly/single_blob.csv"))

    eif_model = H2OExtendedIsolationForestEstimator(ntrees=7, seed=12, sample_size=5)
    eif_model.train(training_frame=train)
    anomaly_score = eif_model.predict(train)
    anomaly = anomaly_score['anomaly_score'].as_data_frame(use_pandas=True)["anomaly_score"]

    print(eif_model)
    
    assert (abs(anomaly[0] - 0.54)) <= 0.01, "Not expected output: Expected value is about 0.54"
    assert (abs(anomaly[5] - 0.47)) <= 0.01, "Not expected output: Expected value is about 0.47"
    assert (abs(anomaly[33] - 0.46)) <= 0.01, "Not expected output: Expected value is about 0.46"
    assert (abs(anomaly[256] - 0.50)) <= 0.01, "Not expected output: Expected value is about 0.50"
    assert (abs(anomaly[499] - 0.50)) <= 0.01, "Not expected output: Expected value is about 0.50"
                                  
                                                             
if __name__ == "__main__":        
    pyunit_utils.standalone_test(extended_isolation_forest)
else:
    extended_isolation_forest()
{'fraction_non_alphanumeric': 0.10992434356920339, 'fraction_numerical': 0.03515798842901647, 'mean_word_length': 4.074492099322799, 'pattern_counts': {'":': 2, '<': 8, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6204335', 'n_tokens_mistral': 808, 'n_tokens_neox': 725, 'n_words': 155}