def test_export_to_python_after_load(): train_pool = Pool(TRAIN_FILE, column_description=CD_FILE) test_pool = Pool(TEST_FILE, column_description=CD_FILE) model = CatBoostClassifier(iterations=40, random_seed=0) model.fit(train_pool) pred_model = model.predict(test_pool, prediction_type='RawFormulaVal') model.save_model(OUTPUT_MODEL_PATH) model_loaded = CatBoostClassifier() model_loaded.load_model(OUTPUT_MODEL_PATH) model_loaded.save_model(OUTPUT_PYTHON_MODEL_PATH, format="python", pool=train_pool) pred_model_loaded = model_loaded.predict(test_pool, prediction_type='RawFormulaVal') import sys import os.path module_dir = os.path.dirname(OUTPUT_PYTHON_MODEL_PATH) sys.path.insert(0, module_dir) from model import apply_catboost_model as apply_catboost_model_from_python pred_python = [] for test_line in test_pool.get_features(): float_features, cat_features = _split_features( test_line, train_pool.get_cat_feature_indices(), test_pool.get_cat_feature_hash_to_string()) pred_python.append( apply_catboost_model_from_python(float_features, cat_features)) assert _check_data(pred_model, pred_python) assert _check_data(pred_model_loaded, pred_python)
def test_export_model_with_only_float_features_to_python_from_python(): train_pool = Pool(HIGGS_TRAIN_FILE, column_description=HIGGS_CD_FILE) test_pool = Pool(HIGGS_TEST_FILE, column_description=HIGGS_CD_FILE) model = CatBoost({'iterations': 30, 'random_seed': 0}) model.fit(train_pool) pred_model = model.predict(test_pool, prediction_type='RawFormulaVal') model.save_model(OUTPUT_PYTHON_MODEL_PATH, format="python") import sys import os.path module_dir = os.path.dirname(OUTPUT_PYTHON_MODEL_PATH) sys.path.insert(0, module_dir) from model import apply_catboost_model as apply_catboost_model_from_python pred_python = [] for float_features in test_pool.get_features(): pred_python.append(apply_catboost_model_from_python(float_features)) assert _check_data(pred_model, pred_python)