(task_type)
| 1355 | |
| 1356 | |
| 1357 | def test_save_load_equality(task_type): |
| 1358 | output_model_path = test_output_path(OUTPUT_MODEL_PATH) |
| 1359 | |
| 1360 | def check_equality(model1, model2): |
| 1361 | assert model1 == model2 |
| 1362 | for attr in ('best_score_', 'evals_result_', 'best_iteration_'): |
| 1363 | assert compare_with_limited_precision(getattr(model1, attr), getattr(model2, attr)) |
| 1364 | |
| 1365 | def check_load_from_stream(model): |
| 1366 | cb_stream = CatBoost() |
| 1367 | with open(output_model_path, 'rb') as stream: |
| 1368 | cb_stream.load_model(stream=stream) |
| 1369 | check_equality(model, cb_stream) |
| 1370 | |
| 1371 | def check_load_from_string(model): |
| 1372 | cb_blob = CatBoost() |
| 1373 | cb_blob.load_model(blob=open(output_model_path, 'rb').read()) |
| 1374 | check_equality(model, cb_blob) |
| 1375 | |
| 1376 | def fill_check_model(params, train_file, test_file, cd_file): |
| 1377 | model, _ = fit_from_file(params, train_file, test_file, cd_file) |
| 1378 | model.save_model(fname=output_model_path) |
| 1379 | check_load_from_string(model) |
| 1380 | check_load_from_stream(model) |
| 1381 | |
| 1382 | fill_check_model({'iterations': 10, 'task_type': task_type, 'gpu_ram_part': TEST_GPU_RAM_PART, 'devices': '0'}, TRAIN_FILE, TEST_FILE, CD_FILE) |
| 1383 | fill_check_model({'loss_function': 'RMSE', 'iterations': 10}, HIGGS_TRAIN_FILE, HIGGS_TEST_FILE, HIGGS_CD_FILE) |
| 1384 | |
| 1385 | params = { |
| 1386 | 'dictionaries': [ |
| 1387 | {'dictionary_id': 'UniGram', 'token_level_type': 'Letter', 'occurrence_lower_bound': '1'}, |
| 1388 | {'dictionary_id': 'BiGram', 'token_level_type': 'Letter', 'occurrence_lower_bound': '1', 'gram_order': '2'}, |
| 1389 | {'dictionary_id': 'Word', 'occurrence_lower_bound': '1'}, |
| 1390 | ], |
| 1391 | 'feature_calcers': ['NaiveBayes', 'BoW:top_tokens_count=10'], |
| 1392 | 'iterations': 10, |
| 1393 | 'loss_function': 'MultiClass', |
| 1394 | 'task_type': task_type, |
| 1395 | 'gpu_ram_part': TEST_GPU_RAM_PART, |
| 1396 | 'devices': '0' |
| 1397 | } |
| 1398 | fill_check_model(params, ROTTEN_TOMATOES_TRAIN_FILE, ROTTEN_TOMATOES_TEST_FILE, ROTTEN_TOMATOES_CD_FILE) |
| 1399 | |
| 1400 | |
| 1401 | def test_load_model_incorrect_argument(task_type): |
nothing calls this directly
no test coverage detected