def create_json_models_files(): """ Creating JSON's files for test before tests. """ chain = create_chain() chain.save('test_chain_convert_to_json') chain_fitted = create_fitted_chain() chain_fitted.save('test_fitted_chain_convert_to_json') chain_empty = Chain() chain_empty.save('test_empty_chain_convert_to_json')
def test_import_custom_json_object_to_chain_and_fit_correctly_no_exception(): test_file_path = str(os.path.dirname(__file__)) file = '../../data/test_custom_json_template.json' json_path_load = os.path.join(test_file_path, file) train_file_path, test_file_path = get_scoring_case_data_paths() train_data = InputData.from_csv(train_file_path) chain = Chain() chain.load(json_path_load) chain.fit(train_data) chain.save( 'test_import_custom_json_object_to_chain_and_fit_correctly_no_exception' )
def test_save_load_fitted_atomized_chain_correctly(): chain = create_chain_with_several_nested_atomized_model() train_data, test_data = create_data_for_train() chain.fit(train_data) json_actual = chain.save('test_save_load_fitted_atomized_chain_correctly') json_path_load = create_correct_path('test_save_load_fitted_atomized_chain_correctly') chain_loaded = Chain() chain_loaded.load(json_path_load) json_expected = chain_loaded.save('test_save_load_fitted_atomized_chain_correctly_loaded') assert chain.length == chain_loaded.length assert json_actual == json_expected before_save_predicted = chain.predict(test_data) chain_loaded.fit(train_data) after_save_predicted = chain_loaded.predict(test_data) bfr_tun_mse = mean_squared_error(y_true=test_data.target, y_pred=before_save_predicted.predict) aft_tun_mse = mean_squared_error(y_true=test_data.target, y_pred=after_save_predicted.predict) assert aft_tun_mse <= bfr_tun_mse
def test_fitted_chain_cache_correctness_after_export_and_import(): train_file_path, test_file_path = get_scoring_case_data_paths() train_data = InputData.from_csv(train_file_path) chain = Chain(PrimaryNode('logit')) chain.fit(train_data) chain.save('test_fitted_chain_cache_correctness_after_export_and_import') json_path_load = create_correct_path( 'test_fitted_chain_cache_correctness_after_export_and_import') new_chain = Chain() new_chain.load(json_path_load) results = new_chain.fit(train_data) assert results is not None
def test_import_json_to_fitted_chain_correctly(): json_path_load = create_correct_path('test_fitted_chain_convert_to_json') chain = Chain() chain.load(json_path_load) json_actual = chain.save('test_import_json_to_fitted_chain_correctly') with open(json_path_load, 'r') as json_file: json_expected = json.load(json_file) assert json_actual == json.dumps(json_expected)
def test_import_json_to_chain_correctly(): json_path_load = create_correct_path('test_chain_convert_to_json') chain = Chain() chain.load(json_path_load) json_actual = chain.save('test_import_json_to_chain_correctly_1') chain_expected = create_chain() json_expected = chain_expected.save( 'test_import_json_to_chain_correctly_2') assert json.dumps(json_actual) == json.dumps(json_expected)