def test_thresholds(fico): threshold_data = threshold.find_thresholds(fico['rocs'], fico['proportions'], fico['base_rate'], fico['base_rates'], COST_MATRIX) assert_deep_almost_equal(FICO_THRESHOLD_DATA, threshold_data, **FICO_TOL)
def test_independence_thresholds(fico): assert_deep_almost_equal( FICO_INDEPENDENCE, threshold.find_independence_thresholds(fico['rocs'], fico['base_rates'], fico['proportions'], COST_MATRIX), **FICO_TOL)
def test_most_similar(w2v_small): POSITIVE, NEGATIVE = ('doctor', 'she'), ('he', ) responsibly_results = most_similar(w2v_small, POSITIVE, NEGATIVE, topn=10) gensim_results = w2v_small.most_similar(POSITIVE, NEGATIVE, topn=9) assert responsibly_results[0][0] == 'doctor' assert_deep_almost_equal(responsibly_results[1:], gensim_results, atol=0.01)
def test_generate_analogies(gender_biased_w2v_small): """Test generate_analogies method in GenderBiasWE. Based on: https://github.com/tolga-b/debiaswe/blob/master/tutorial_example1.ipynb """ analogies_df = (gender_biased_w2v_small.generate_analogies( 500, unrestricted=False)) analogies_df = analogies_df[['she', 'he']] assert_deep_almost_equal(analogies_df.values, TOLGA_GENDER_ANALOGIES)
def test_calc_all_weat_defaults(w2v_small): weat_5_results_default = (calc_all_weat(w2v_small, (5, )).iloc[0].to_dict()) weat_5_results = (calc_all_weat(w2v_small, (5, ), filter_by='model', with_pvalue=True, pvalue_kwargs={ 'method': 'exact' }).iloc[0].to_dict()) assert_deep_almost_equal(weat_5_results_default, weat_5_results)
def test_calc_weat_pleasant_attribute(w2v_small): # pylint: disable=line-too-long pvalue_kwargs = {'method': 'approximate'} result_v1 = calc_weat_pleasant_unpleasant_attribute( w2v_small, WEAT_DATA[1]['first_target'], WEAT_DATA[1]['second_target'], pvalue_kwargs=pvalue_kwargs) result_v1['p'] = round(result_v1['p'], 4) result_v1['d'] = round(result_v1['d'], 4) result_v1['s'] = round(result_v1['s'], 4) result_v2 = (calc_all_weat(w2v_small, (1, ), pvalue_kwargs=pvalue_kwargs).iloc[0].to_dict()) assert_deep_almost_equal(result_v1, result_v2, atol=0.01)
def test_calc_all_weat_index(w2v_small): all_weat = calc_all_weat(w2v_small, filter_by='model', with_original_finding=True, with_pvalue=True, pvalue_kwargs={'method': 'approximate'}) for index in range(len(WEAT_DATA)): single_weat = calc_all_weat(w2v_small, weat_data=index, filter_by='model', with_original_finding=True, with_pvalue=True, pvalue_kwargs={'method': 'approximate'}) assert_deep_almost_equal(single_weat.iloc[0].to_dict(), all_weat.iloc[index].to_dict(), atol=0.01)
def test_separation_thresholds(fico): assert_deep_almost_equal( FICO_SEPARATION, threshold.find_separation_thresholds(fico['rocs'], fico['base_rate'], COST_MATRIX), **FICO_TOL)
def test_fnr_thresholds(fico): assert_deep_almost_equal( FICO_FNR, threshold.find_fnr_thresholds(fico['rocs'], fico['base_rates'], fico['proportions'], COST_MATRIX), **FICO_TOL)
def test_min_cost_threshold(fico): assert_deep_almost_equal( FICO_MIN_COST, threshold.find_min_cost_thresholds(fico['rocs'], fico['base_rates'], fico['proportions'], COST_MATRIX), **FICO_TOL)
def test_single_threshold(fico): assert_deep_almost_equal( FICO_SINGLE, threshold.find_single_threshold(fico['rocs'], fico['base_rates'], fico['proportions'], COST_MATRIX), **FICO_TOL)