def train_test_classifier():
     w = ut.train_model(x_train, y_train, x_control_train, loss_function,
                        apply_fairness_constraints,
                        apply_accuracy_constraint, sep_constraint,
                        sensitive_attrs, sensitive_attrs_to_cov_thresh,
                        gamma)
     train_score, test_score, correct_answers_train, correct_answers_test = ut.check_accuracy(
         w, x_train, y_train, x_test, y_test, None, None)
     distances_boundary_test = (np.dot(x_test, w)).tolist()
     all_class_labels_assigned_test = np.sign(distances_boundary_test)
     correlation_dict_test = ut.get_correlations(
         None, None, all_class_labels_assigned_test, x_control_test,
         sensitive_attrs)
     cov_dict_test = ut.print_covariance_sensitive_attrs(
         None, x_test, distances_boundary_test, x_control_test,
         sensitive_attrs)
     p_rule = ut.print_classifier_fairness_stats([test_score],
                                                 [correlation_dict_test],
                                                 [cov_dict_test],
                                                 sensitive_attrs[0])
     eq_op_acc, chance_bin_zero, chance_bin_one = ut.get_eq_op_acc(
         w, x_train, y_train, x_control_train, None)
     eq_odds_acc = ut.get_eq_odds_acc(w, x_train, y_train, x_control_train,
                                      None)
     pred_rate_par_acc = ut.get_pred_rate_par_acc(w, x_train, y_train,
                                                  x_control_train, None)
     demo_par_acc_f_cons = ut.get_dem_par_acc(w, x_train, y_train,
                                              x_control_train, None)
     return w, p_rule, test_score, eq_op_acc, eq_odds_acc, pred_rate_par_acc, demo_par_acc_f_cons
def test_classifier(w, x, y, control, sensitive_attrs):
    distances_boundary_test = (np.dot(x, w)).tolist()
    all_class_labels_assigned_test = np.sign(distances_boundary_test)
    test_score, _ = check_accuracy(w, x, y)
    correlation_dict_test = ut.get_correlations(None, None, all_class_labels_assigned_test, control, sensitive_attrs)
    cov_dict_test = ut.print_covariance_sensitive_attrs(None, x, distances_boundary_test, control, sensitive_attrs)
    p_rule = ut.print_classifier_fairness_stats([test_score], [correlation_dict_test], [cov_dict_test], sensitive_attrs[0])
    return p_rule, test_score
	def train_test_classifier():
		w = ut.train_model(x_train, y_train, x_control_train, loss_function, apply_fairness_constraints, apply_accuracy_constraint, sep_constraint, sensitive_attrs, sensitive_attrs_to_cov_thresh, gamma)
		train_score, test_score, correct_answers_train, correct_answers_test = ut.check_accuracy(w, x_train, y_train, x_test, y_test, None, None)
		distances_boundary_test = (np.dot(x_test, w)).tolist()
		all_class_labels_assigned_test = np.sign(distances_boundary_test)
		correlation_dict_test = ut.get_correlations(None, None, all_class_labels_assigned_test, x_control_test, sensitive_attrs)
		cov_dict_test = ut.print_covariance_sensitive_attrs(None, x_test, distances_boundary_test, x_control_test, sensitive_attrs)
		p_rule = ut.print_classifier_fairness_stats([test_score], [correlation_dict_test], [cov_dict_test], sensitive_attrs[0])	
		return w, p_rule, test_score
Example #4
0
 def train_test_classifier():
     w = ut.train_model(x_train, y_train, x_control_train, loss_function, apply_fairness_constraints, apply_accuracy_constraint, sep_constraint, sensitive_attrs, sensitive_attrs_to_cov_thresh, gamma)
     train_score, test_score, correct_answers_train, correct_answers_test = ut.check_accuracy(w, x_train, y_train, x_test, y_test, None, None)
     distances_boundary_test = np.dot(x_test, w)
     distances_boundary_train = np.dot(x_train, w)
     prob_test = [sigmoid(x) for x in distances_boundary_test]
     prob_train = [sigmoid(x) for x in distances_boundary_train]
     all_class_labels_assigned_test = np.sign(distances_boundary_test)
     correlation_dict_test = ut.get_correlations(None, None, all_class_labels_assigned_test, x_control_test, sensitive_attrs)
     cov_dict_test = ut.print_covariance_sensitive_attrs(None, x_test, distances_boundary_test, x_control_test, sensitive_attrs)
     p_rule = ut.print_classifier_fairness_stats([test_score], [correlation_dict_test], [cov_dict_test], sensitive_attrs[0])	
     # return w, p_rule, test_score
     return prob_train, prob_test