<filename>h2o-py/tests/testdir_misc/pyunit_pubdev_7506_model_download_with_cv.py<gh_stars>1000+
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import h2o
import os
from h2o.estimators.gbm import H2OGradientBoostingEstimator
from tests import pyunit_utils


def model_download_with_cv():
    prostate = h2o.import_file(pyunit_utils.locate("smalldata/prostate/prostate.csv"))
    prostate["CAPSULE"] = prostate["CAPSULE"].asfactor()

    prostate_gbm = H2OGradientBoostingEstimator(nfolds=2, keep_cross_validation_predictions=True)
    prostate_gbm.train(x=["AGE", "RACE", "PSA", "DCAPS"], y="CAPSULE", training_frame=prostate)
    path = pyunit_utils.locate("results")

    model_path = h2o.download_model(prostate_gbm, path=path, export_cross_validation_predictions=True)
    assert os.path.isfile(model_path), "Expected model artifact {0} to exist, but it does not.".format(model_path)

    h2o.remove_all()

    prostate_gbm_reloaded = h2o.upload_model(model_path)
    assert isinstance(prostate_gbm_reloaded, H2OGradientBoostingEstimator), \
        "Expected H2OGradientBoostingEstimator, but got {0}".format(prostate_gbm_reloaded)

    holdout_frame_id = prostate_gbm.cross_validation_holdout_predictions().frame_id
    assert h2o.get_frame(holdout_frame_id) is not None


if __name__ == "__main__":
    pyunit_utils.standalone_test(model_download_with_cv)
else:
    model_download_with_cv()

<filename>h2o-py/tests/testdir_misc/pyunit_pubdev_7506_model_download_with_cv.py<gh_stars>1000+
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import h2o
import os
from h2o.estimators.gbm import H2OGradientBoostingEstimator
from tests import pyunit_utils


def model_download_with_cv():
    prostate = h2o.import_file(pyunit_utils.locate("smalldata/prostate/prostate.csv"))
    prostate["CAPSULE"] = prostate["CAPSULE"].asfactor()

    prostate_gbm = H2OGradientBoostingEstimator(nfolds=2, keep_cross_validation_predictions=True)
    prostate_gbm.train(x=["AGE", "RACE", "PSA", "DCAPS"], y="CAPSULE", training_frame=prostate)
    path = pyunit_utils.locate("results")

    model_path = h2o.download_model(prostate_gbm, path=path, export_cross_validation_predictions=True)
    assert os.path.isfile(model_path), "Expected model artifact {0} to exist, but it does not.".format(model_path)

    h2o.remove_all()

    prostate_gbm_reloaded = h2o.upload_model(model_path)
    assert isinstance(prostate_gbm_reloaded, H2OGradientBoostingEstimator), \
        "Expected H2OGradientBoostingEstimator, but got {0}".format(prostate_gbm_reloaded)

    holdout_frame_id = prostate_gbm.cross_validation_holdout_predictions().frame_id
    assert h2o.get_frame(holdout_frame_id) is not None


if __name__ == "__main__":
    pyunit_utils.standalone_test(model_download_with_cv)
else:
    model_download_with_cv()

#!/usr/bin/env python # -*- encoding: utf-8 -*-