MAJ terminée. Nous sommes passés en version 14.6.2 . Pour consulter les "releases notes" associées c'est ici :

https://about.gitlab.com/releases/2022/01/11/security-release-gitlab-14-6-2-released/
https://about.gitlab.com/releases/2022/01/04/gitlab-14-6-1-released/

Commit 0f79e17c authored by BERNIER Fabien's avatar BERNIER Fabien
Browse files

[~] reorganization of the project structure

parent 9e960077
......@@ -3,11 +3,10 @@
import copy
import sklearn
import numpy as np
import lime
import lime.lime_tabular
import fixout.lime.lime_tabular
# import string
import os
import sys
class Bunch(object):
"""bla"""
......@@ -257,9 +256,9 @@ def load_csv_dataset(data, target_idx, delimiter=',',
data = data.astype(float)
ordinal_features = []
if discretize:
disc = lime.lime_tabular.QuartileDiscretizer(data,
categorical_features,
feature_names)
disc = fixout.lime.lime_tabular.QuartileDiscretizer(data,
categorical_features,
feature_names)
data = disc.discretize(data)
ordinal_features = [x for x in range(data.shape[1])
if x not in categorical_features]
......@@ -316,7 +315,7 @@ def load_csv_dataset(data, target_idx, delimiter=',',
class Neighbors:
def __init__(self, nlp_obj):
self.nlp = nlp_obj
self.to_check = [w for w in self.nlp.vocab if w.prob >= -15 and w.has_vector]
self.to_check = [w for w in self.nlp.vocab if w.predict_proba >= -15 and w.has_vector]
if not self.to_check:
raise Exception('No vectors. Are you using en_core_web_sm? It should be en_core_web_lg')
self.n = {}
......@@ -333,7 +332,7 @@ class Neighbors:
word = self.nlp.vocab[word]
queries = [w for w in self.to_check
if w.is_lower == word.is_lower]
if word.prob < -15:
if word.predict_proba < -15:
queries += [word]
by_similarity = sorted(
queries, key=lambda w: word.similarity(w), reverse=True)
......
......@@ -5,19 +5,18 @@ import random
import oapackage
from anchor import anchor_tabular
import lime_global
import matplotlib.pyplot as plt
from fixout.anchor import anchor_tabular
from fixout import lime_global
import numpy as np
import pandas as pd
def fairness_eval(model, train, max_features, sensitive_features, feature_names, class_names, categorical_features, categorical_names, sample_size):
_, sp_obj = lime_global.features_contributions(model.prob, train, feature_names, max_features, class_names, categorical_features, categorical_names, sample_size)
_, sp_obj = lime_global.features_contributions(model.predict_proba, train, feature_names, max_features, class_names, categorical_features, categorical_names, sample_size)
indices = sp_obj.indices
a_explainers = anchor_tabular.AnchorTabularExplainer(class_names,feature_names,train,categorical_names=categorical_names)
a_explainers = anchor_tabular.AnchorTabularExplainer(class_names, feature_names, train, categorical_names=categorical_names)
non_empty_anchors = 0
counter = Counter()
......@@ -56,7 +55,7 @@ def fairness_eval2(model, train, max_features, sensitive_features, feature_names
# indices = sp_obj.indices
indices = random.choices(range(len(train)), k=sample_size)
# indices = list(range(800))
a_explainers = anchor_tabular.AnchorTabularExplainer(class_names,feature_names,train,categorical_names=categorical_names)
a_explainers = anchor_tabular.AnchorTabularExplainer(class_names, feature_names, train, categorical_names=categorical_names)
anchors_pos = []
anchors_neg = []
......
......@@ -3,21 +3,13 @@ Implements the main procedures to build fairer ensembles, e.g. feature drop out,
"""
import os
from aif360.sklearn.metrics.metrics import statistical_parity_difference, \
equal_opportunity_difference, average_odds_difference, \
disparate_impact_ratio, difference, generalized_fpr, specificity_score
from aif360.sklearn.utils import check_groups
from sklearn.metrics import accuracy_score
from sklearn.metrics import f1_score
from sklearn.metrics._classification import confusion_matrix
from sklearn.model_selection._split import train_test_split
from sklearn.preprocessing._encoders import OneHotEncoder
from sklearn.preprocessing._label import LabelEncoder
from lime_text_global import fairness_eval
from fixout.lime_text_global import fairness_eval
from copy import deepcopy
import numpy as np
import pandas as pd
import re
......@@ -54,7 +46,7 @@ class FixOutText:
model = train_classifier(self.algo, self.train, self.train_labels)
self.original_model = Model([model], [None])
accuracy, threshold = evaluation(self.original_model.prob(self.test), self.test_labels)
accuracy, threshold = evaluation(self.original_model.predict_proba(self.test), self.test_labels)
actual_sensitive, is_fair_flag, ans_data, explainer = self.exp(self.original_model, self.train, self.max_features, self.sensitive_f, self.feature_names, self.class_names, self.sampling_size, self.threshold)
return actual_sensitive, is_fair_flag, ans_data, accuracy, threshold
......@@ -94,13 +86,13 @@ class FixOutText:
removers.append(rep_all)
self.ensemble = Model(models, removers)
accuracy, threshold = evaluation(self.ensemble.prob(self.test), self.test_labels)
accuracy, threshold = evaluation(self.ensemble.predict_proba(self.test), self.test_labels)
_, is_fair_flag, ans_data, explainer = self.exp(self.ensemble, self.train, self.max_features, actual_sensitive, self.feature_names, self.class_names, self.sampling_size, self.threshold)
return is_fair_flag, ans_data, accuracy, threshold
class Model:
class EnsembleOut:
"""Class for ensemble models
Saves a list of trained classifiers and their respective encoders and deleted features
......@@ -113,8 +105,7 @@ class Model:
self.models = models
self.removers = removers
def prob(self, X):
def predict_proba(self, X):
"""
Returns probability for each class label.
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment