예제 #1
0
from load_data import load_heart_uci
from measures import equalized_odds_measure_TP, equalized_odds_measure_FP, \
    statistical_parity_measure, disparate_impact_measure

from sklearn import svm
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn.decomposition import PCA
from sklearn.preprocessing import MinMaxScaler

set_of_exps = 2

if set_of_exps == 1:
    dataset = load_heart_uci()
    scaler = MinMaxScaler(feature_range=(-1, 1))
    dataset.data = scaler.fit(dataset.data).transform(dataset.data)
    # print(heart.data[1, :], heart.data[2, :], heart.data[3, :])
    # % for train
    ntrain = 5 * len(
        dataset.target
    ) // 10  # from 30% to 50% the accuracy is the same BUT more fairness!

    # Train an SVM using the training set
    clf = svm.SVC(C=1.0)
    clf.fit(dataset.data[:ntrain, :], dataset.target[:ntrain])

    # The dataset becomes the test set
    dataset.data = dataset.data[ntrain:, :]
    dataset.target = dataset.target[ntrain:]
        self.model.fit(self.dataset.data, self.dataset.target)
        #if hasattr(self.model, 'best_estimator_'):
        #    self.model = self.model.best_estimator_
        #self.coef_ = self.model.coef_
        #self.intercept_ = self.model.intercept_


if __name__ == "__main__":
    experiment_number = 0
    if experiment_number == 0:
        dataset_train = load_binary_diabetes_uci()
        dataset_test = load_binary_diabetes_uci()
        sensible_feature = 1  # sex
    elif experiment_number == 1:
        dataset_train = load_heart_uci()
        dataset_test = load_heart_uci()
        sensible_feature = 1  # sex
    elif experiment_number == 2:
        dataset_train, dataset_test = load_adult(smaller=False)
        sensible_feature = 9  # sex
        print('Different values of the sensible feature', sensible_feature,
              ':', set(dataset_train.data[:, sensible_feature]))
    elif experiment_number == 3:
        dataset_train, dataset_test = load_adult_race(smaller=False)
        sensible_feature = 8  # race
        print('Different values of the sensible feature', sensible_feature,
              ':', set(dataset_train.data[:, sensible_feature]))

    if experiment_number in [0, 1]:
        # % for train