def train_classifier(X_train, X_test, y_train, y_test, sa_index, p_Group, dataset, mutex, mode, base_learners): if mode == 0: classifier = AdaFairNoCumul(n_estimators=base_learners, saIndex=sa_index, saValue=p_Group, CSB="CSB2") elif mode == 1: classifier = AdaFair(n_estimators=base_learners, saIndex=sa_index, saValue=p_Group, CSB="CSB2") classifier.fit(X_train, y_train) y_pred_probs = classifier.predict_proba(X_test)[:, 1] y_pred_labels = classifier.predict(X_test) mutex.acquire() infile = open(dataset, 'rb') dict_to_ram = pickle.load(infile) infile.close() dict_to_ram.performance.append( calculate_performance(X_test, y_test, y_pred_labels, y_pred_probs, sa_index, p_Group)) outfile = open(dataset, 'wb') pickle.dump(dict_to_ram, outfile) outfile.close() mutex.release()
def predict(clf, X_test, y_test, sa_index, p_Group): y_pred_probs = clf.predict_proba(X_test)[:, 1] y_pred_labels = clf.predict(X_test) return calculate_performance(X_test, y_test, y_pred_labels, y_pred_probs, sa_index, p_Group)