src.model.deeplearn.handle.dl_class_weighter
Classes
- class src.model.deeplearn.handle.dl_class_weighter.DLClassWeighter
- Author:
Alberto M. Esmoris Pena
Class to handle class weights for deep learning models.
- __init__()
- handle_class_weight(mh, y)
Handle the class weight parameter of a deep learning model’s handler.
If no class weight is requested, then class weight will be None.
If automatic class weight is requested (i.e., “auto”), then the class weight is automatically determined from the distribution of expected classes to give a greater weight to less frequent classes and a smaller weight to more frequent classes. More concretely, let \(m\) be the number of samples, \(m_i\) be the number of samples corresponding to class \(i\), and \(n\) be the number of classes. Thus, each class weight will be \(w_i = m/(n m_i)\).
If class weight is a list, tuple or array of weights it will be translated to a dictionary such that the first element is the weight for the first class, and so on.
- Parameters:
mh – The model handler whose class weights must be handled.
y (
np.ndarray) – The vector of expected point-wise classes.
- Returns:
Class weight prepared for the model.