11 This class provides a fast implementation of equal frequency binning.
12 In Equal frequency binning the binning is chosen in a way that every bin has the same number of entries.
13 An example with a Neural Network can be found in: mva/examples/keras/preprocessing.py
19 If you saved a state before and wants to rebuild the class use the state parameter.
23 self.
state = {
'binning_array': [],
'number_of_bins': 0}
27 def fit(self, x, number_of_bins=100):
29 Do the fitting -> calculate binning boundaries
31 for variable
in range(len(x[0, :])):
32 self.
state[
'binning_array'].append(np.percentile(np.nan_to_num(x[:, variable]),
33 np.linspace(0, 100, number_of_bins + 1)))
34 self.
state[
'number_of_bins'] = number_of_bins
40 for variable
in range(len(x[0, :])):
41 x[:, variable] = np.digitize(np.nan_to_num(x[:, variable]),
42 self.
state[
'binning_array'][variable][1:-1]) / self.
state[
'number_of_bins']
47 Returns a pickable dictionary to save the state of the class in a mva weightfile