-
Notifications
You must be signed in to change notification settings - Fork 0
/
adult.py
60 lines (46 loc) · 1.7 KB
/
adult.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from NN_Classifier import *
from NN_Regressor import *
from CounterfactualSurrogateModel import *
import time
N_SAMPES = 1500
# # # -------------------------------
model_category_features = ['workclass', 'education', 'marital-status', 'occupation','relationship', 'race', 'sex', 'native-country']
model_continous_features = ['age','fnlwgt','capital-gain','capital-loss','hours-per-week','education-num']
model = NN_Classifier('adult',
hidden_layer_sizes=(50, 50, 50, 50, 50, 50, 50, 50, 100, 100 ),
categorical_features=model_category_features,
continous_features=model_continous_features
)
model.load_data()
model.split_data()
# model.train()
model.loadModel()
model.evaluate()
start_time = time.time()
print("STARTING GENERATION 1")
model_data = model.getGlobalRandomSample(n_samples=N_SAMPES)
print(model_data)
model_surrogateModel = CountefactualSurrogateModel('adult',
fileModifer=f"global-{N_SAMPES}",
categorical_features=model.categorical_features,
continous_features=model.continous_features,
className="class",
regression=False,
n_samples=1
)
model_surrogateModel.loadModel(model.clf)
model_surrogateModel.loadDataSet(model_data)
# model_surrogateModel.generate(scale=1)
print("STARTING GENERATION 2")
model_surrogateModel.loadData(
path=f"counterfactuals/{model_surrogateModel.fileModifer}-{model.name}-1.csv")
model_surrogateModel.n_samples = 1
# model_surrogateModel.generate(scale=1, generation=2)
print("CounterFactual")
model_surrogateModel.generateTree(dataset=[1, 2])
print("Control")
model_surrogateModel.generateTree(
localisedData=model_data)
end_time = time.time()
print("Elapsed time: ", end_time - start_time, "seconds")
print(f"SampleSize : {N_SAMPES}")