Belle II Software development
fast_equal_frequency_binning Class Reference

Public Member Functions

 __init__ (self, state=None)
 
 fit (self, x, number_of_bins=100)
 
 apply (self, x)
 
 export_state (self)
 

Public Attributes

dict state = {'binning_array': [], 'number_of_bins': 0}
 State of the class.
 

Detailed Description

This class provides a fast implementation of equal frequency binning.
In Equal frequency binning the binning is chosen in a way that every bin has the same number of entries.
An example with a Neural Network can be found in: mva/examples/keras/preprocessing.py

Definition at line 14 of file preprocessing.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
state = None )
Init the class.
If you saved a state before and wants to rebuild the class use the state parameter.

Definition at line 21 of file preprocessing.py.

21 def __init__(self, state=None):
22 """
23 Init the class.
24 If you saved a state before and wants to rebuild the class use the state parameter.
25 """
26 if state is None:
27
28 self.state = {'binning_array': [], 'number_of_bins': 0}
29 else:
30 self.state = state
31

Member Function Documentation

◆ apply()

apply ( self,
x )
Bin a dataset

Definition at line 41 of file preprocessing.py.

41 def apply(self, x):
42 """
43 Bin a dataset
44 """
45 for variable in range(len(x[0, :])):
46 x[:, variable] = np.digitize(np.nan_to_num(x[:, variable]),
47 self.state['binning_array'][variable][1:-1]) / self.state['number_of_bins']
48 return x
49

◆ export_state()

export_state ( self)
Returns a pickable dictionary to save the state of the class in a mva weightfile

Definition at line 50 of file preprocessing.py.

50 def export_state(self):
51 """
52 Returns a pickable dictionary to save the state of the class in a mva weightfile
53 """
54 return self.state

◆ fit()

fit ( self,
x,
number_of_bins = 100 )
Do the fitting -> calculate binning boundaries

Definition at line 32 of file preprocessing.py.

32 def fit(self, x, number_of_bins=100):
33 """
34 Do the fitting -> calculate binning boundaries
35 """
36 for variable in range(len(x[0, :])):
37 self.state['binning_array'].append(np.percentile(np.nan_to_num(x[:, variable]),
38 np.linspace(0, 100, number_of_bins + 1)))
39 self.state['number_of_bins'] = number_of_bins
40

Member Data Documentation

◆ state

dict state = {'binning_array': [], 'number_of_bins': 0}

State of the class.

This will be saved

Definition at line 28 of file preprocessing.py.


The documentation for this class was generated from the following file: