def test_visualize_feature_remove_na(): loan_data_dup = pandas.DataFrame() loan_data_dup["emp_length_int"] = loan_data["emp_length_int"] loan_data_dup = pandas.concat([ loan_data_dup, pandas.DataFrame([numpy.nan] * 250, columns=["emp_length_int"]) ], ignore_index=True).sample(frac=1, random_state=0) assert loan_data_dup["emp_length_int"].isna().sum() == 250 visualize_feature(loan_data_dup["emp_length_int"], remove_na=True) result_path = Path(__file__).parents[0].absolute().joinpath( "result_images").joinpath("test_visualization_aids").joinpath( "test_visualize_feature_remove_na.png") pyplot.savefig(str(result_path)) baseline_path = Path(__file__).parents[0].absolute().joinpath( "baseline_images").joinpath("test_visualization_aids").joinpath( "test_visualize_feature_remove_na.png") pyplot.cla() pyplot.close(pyplot.gcf()) compare_images_from_paths(str(baseline_path), str(result_path))
def test_visualize_feature_int(): visualize_feature(loan_data["loan_condition_cat"]) result_path = Path(__file__).parents[0].absolute().joinpath( "result_images").joinpath("test_visualization_aids").joinpath( "test_visualize_feature_int.png") pyplot.savefig(str(result_path)) baseline_path = Path(__file__).parents[0].absolute().joinpath( "baseline_images").joinpath("test_visualization_aids").joinpath( "test_visualize_feature_int.png") pyplot.cla() pyplot.close(pyplot.gcf()) compare_images_from_paths(str(baseline_path), str(result_path))
def test_visualize_feature_object(): visualize_feature(loan_data["income_category"]) result_path = Path(__file__).parents[0].absolute().joinpath( "result_images").joinpath("test_visualization_aids").joinpath( "test_visualize_feature_object.png") pyplot.gcf().set_size_inches(10, 8) pyplot.savefig(str(result_path)) baseline_path = Path(__file__).parents[0].absolute().joinpath( "baseline_images").joinpath("test_visualization_aids").joinpath( "test_visualize_feature_object.png") pyplot.cla() pyplot.close(pyplot.gcf()) compare_images_from_paths(str(baseline_path), str(result_path))
def test_visualize_feature_category_more_than_10_categories(): visualize_feature(loan_data["purpose"].astype("category")) result_path = Path(__file__).parents[0].absolute().joinpath( "result_images").joinpath("test_visualization_aids").joinpath( "test_visualize_feature_category_more_than_10_categories.png") pyplot.gcf().set_size_inches(11, 11) pyplot.savefig(str(result_path)) baseline_path = Path(__file__).parents[0].absolute().joinpath( "baseline_images").joinpath("test_visualization_aids").joinpath( "test_visualize_feature_category_more_than_10_categories.png") pyplot.cla() pyplot.close(pyplot.gcf()) compare_images_from_paths(str(baseline_path), str(result_path))
def test_visualize_feature_bool(): loan_dup = pandas.DataFrame() loan_dup["term 36 months"] = loan_data["term"].apply( lambda term: True if term == " 36 months" else False).astype("bool") visualize_feature(loan_dup["term 36 months"]) result_path = Path(__file__).parents[0].absolute().joinpath( "result_images").joinpath("test_visualization_aids").joinpath( "test_visualize_feature_bool.png") pyplot.savefig(str(result_path)) baseline_path = Path(__file__).parents[0].absolute().joinpath( "baseline_images").joinpath("test_visualization_aids").joinpath( "test_visualize_feature_bool.png") pyplot.cla() pyplot.close(pyplot.gcf()) compare_images_from_paths(str(baseline_path), str(result_path))
def test_visualize_feature_float_exist_ax(): pyplot.figure() ax = pyplot.gca() ax.set_title("My ax") visualize_feature(loan_data["emp_length_int"], ax=ax) result_path = Path(__file__).parents[0].absolute().joinpath( "result_images").joinpath("test_visualization_aids").joinpath( "test_visualize_feature_float_exist_ax.png") pyplot.gcf().set_size_inches(10, 8) pyplot.savefig(str(result_path)) baseline_path = Path(__file__).parents[0].absolute().joinpath( "baseline_images").joinpath("test_visualization_aids").joinpath( "test_visualize_feature_float_exist_ax.png") pyplot.cla() pyplot.close(pyplot.gcf()) compare_images_from_paths(str(baseline_path), str(result_path))