-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompas_SVM.py
30 lines (19 loc) · 1.06 KB
/
Compas_SVM.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from sklearn import svm
from Preprocessing import preprocess
from Report_Results import report_results
import numpy as np
from utils import *
def SVM_classification(metrics):
training_data, training_labels, test_data, test_labels, categories, mappings = preprocess(metrics, recalculate=False, causal=False)
np.random.seed(42)
SVR = svm.LinearSVR(C=1.0/float(len(test_data)), max_iter=5000)
SVR.fit(training_data, training_labels)
data = np.concatenate((training_data, test_data))
labels = np.concatenate((training_labels, test_labels))
predictions = SVR.predict(data)
return data, predictions, labels, categories, mappings
#######################################################################################################################
metrics = ["sex", "age_cat", 'race', 'c_charge_degree', 'priors_count']
data, predictions, labels, categories, mappings = SVM_classification(metrics)
race_cases = get_cases_by_metric(data, categories, "race", mappings, predictions, labels)
report_results(race_cases)