-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathive_example.py
39 lines (29 loc) · 1.06 KB
/
ive_example.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
# Example of Incremental Variable Elimination
#
# For further information please refer to:
# "Suppressing Gender and Age in Face Templates Using Incremental Variable Elimination" by
# Philipp Terhörst, Naser Damer, Florian Kirchbuchner and Arjan Kuijper,
# International Conference on Biometrics (ICB), 2019
#
import numpy as np
from sklearn.ensemble import RandomForestClassifier
from sklearn.preprocessing import StandardScaler
from incremental_variable_elimination import IncrementalVariableElimination as IVE
# load data
# in this example we use only a small subset
X = np.load("sample_features.npy")
Y = np.load("sample_gender_labels.npy")
# feature normalization
scaler = StandardScaler()
X = scaler.fit_transform(X)
# define classifier
model_train = RandomForestClassifier(n_estimators=30)
# define params
# number of steps and number of eliminations per step have to be
# adjusted depending on the feature size
num_steps = 20
num_eliminations = 5
# init, fit and transform
ive = IVE(model_train, num_eliminations, num_steps)
ive.fit(X,Y)
X_new = ive.transform(X)