def create_json_models_files(): """ Creating JSON's files for test before tests. """ pipeline = create_pipeline() pipeline.save('test_pipeline_convert_to_json') pipeline_fitted = create_fitted_pipeline() pipeline_fitted.save('test_fitted_pipeline_convert_to_json') pipeline_empty = Pipeline() pipeline_empty.save('test_empty_pipeline_convert_to_json')
def test_import_custom_json_object_to_pipeline_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) pipeline = Pipeline() pipeline.load(json_path_load) pipeline.fit(train_data) pipeline.save('test_import_custom_json_object_to_pipeline_and_fit_correctly_no_exception')
def test_save_load_fitted_atomized_pipeline_correctly(): pipeline = create_pipeline_with_several_nested_atomized_model() train_data, test_data = create_data_for_train() pipeline.fit(train_data) json_actual = pipeline.save( 'test_save_load_fitted_atomized_pipeline_correctly') json_path_load = create_correct_path( 'test_save_load_fitted_atomized_pipeline_correctly') pipeline_loaded = Pipeline() pipeline_loaded.load(json_path_load) json_expected = pipeline_loaded.save( 'test_save_load_fitted_atomized_pipeline_correctly_loaded') assert pipeline.length == pipeline_loaded.length assert json_actual == json_expected before_save_predicted = pipeline.predict(test_data) pipeline_loaded.fit(train_data) after_save_predicted = pipeline_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_import_json_to_fitted_pipeline_correctly(): json_path_load = create_correct_path('test_fitted_pipeline_convert_to_json') pipeline = Pipeline() pipeline.load(json_path_load) json_actual = pipeline.save('test_import_json_to_fitted_pipeline_correctly') with open(json_path_load, 'r') as json_file: json_expected = json.load(json_file) assert json_actual == json.dumps(json_expected, indent=4)
def test_import_json_to_pipeline_correctly(): json_path_load = create_correct_path('test_pipeline_convert_to_json') pipeline = Pipeline() pipeline.load(json_path_load) json_actual = pipeline.save('test_import_json_to_pipeline_correctly_1') pipeline_expected = create_pipeline() json_expected = pipeline_expected.save('test_import_json_to_pipeline_correctly_2') assert json.dumps(json_actual) == json.dumps(json_expected)