def test3_misclass_rate_feature(dataset_categorical, dataset_predictions_categorical): """Checks for assertions that should be true for specific parameter combinations.""" result_edges, result_rate, result_sd = misclass_rate_feature( dataset_categorical, dataset_predictions_categorical, feature="Feature 1", categorical=True, ) result_edges_scenario = ["blue", "green", "red"] result_rate_scenario = [0.6667, 0.0, 1.0] result_sd_scenario = [0.8563, float("nan"), 2.0] # All results should have the expected number of elements assert len(result_edges) == len(result_edges_scenario) assert len(result_rate) == len(result_rate_scenario) assert len(result_sd) == len(result_sd_scenario) # All the elements of the three results should agree with the written values # up to 0,1% (10^-3). np.testing.assert_array_equal(result_edges, result_edges_scenario) np.testing.assert_allclose(result_rate, result_rate_scenario, rtol=1e-03, equal_nan=True) np.testing.assert_allclose(result_sd, result_sd_scenario, rtol=1e-03, equal_nan=True)
def test1_misclass_rate_feature(dataset, dataset_predictions, feature_param, bins_param, bins_type_param): """Checks for assertions that should always apply regardless of the dataset and the parameters. """ result_edges, result_rate, result_sd = misclass_rate_feature( dataset, dataset_predictions, feature=feature_param, bins=bins_param, bins_type=bins_type_param, ) assert len(result_edges) == len(result_rate) + 1 if type(bins_param) == int: assert len(result_rate) == bins_param elif type(bins_param) == list: assert len(result_rate) == len(bins_param) - 1 assert max(result_rate) <= 1.0 assert min(result_rate) >= 0.0
def test2_misclass_rate_feature( dataset, dataset_predictions, feature_scenario, categorical_scenario, bins_scenario, bins_type_scenario, result_edges_scenario, result_rate_scenario, result_sd_scenario, ): """Checks for assertions that should be true for specific parameter combinations.""" result_edges, result_rate, result_sd = misclass_rate_feature( dataset, dataset_predictions, feature_scenario, categorical=categorical_scenario, bins=bins_scenario, bins_type=bins_type_scenario, ) # All results should have the expected number of elements assert len(result_edges) == len(result_edges_scenario) assert len(result_rate) == len(result_rate_scenario) assert len(result_sd) == len(result_sd_scenario) # All the elements of the three results should agree with the written values # up to 0,1% (10^-3). np.testing.assert_allclose(result_edges, result_edges_scenario, rtol=1e-03, equal_nan=True) np.testing.assert_allclose(result_rate, result_rate_scenario, rtol=1e-03, equal_nan=True) np.testing.assert_allclose(result_sd, result_sd_scenario, rtol=1e-03, equal_nan=True)