Skip to content

Reclassifying Labels

Reclassifying Labels

For classification ML models, the labels begin with 0, for our data that would represent 0 number of tracks. For this reason though the experimental labels begin with 1, we subtract 1 from them for ML purposes.

Bases: BaseEstimator, TransformerMixin

Parameters

None

Return

X_copy: (np.array) Labels recalculated but the same data shape remains same (run_events, target_size,4)

Source code in scripts/ml_preprocessing_steps.py
class ReclassifyingLabels(BaseEstimator,TransformerMixin):
    """
    Parameters
    ----------
    None

    Return
    ----------
    X_copy: (np.array) 
        Labels recalculated but the same data shape remains same  (run_events, target_size,4) 

    """
    def __init__(self):
        pass

    def fit(self,X,y=None):
        return self 

    def transform(self, X,y=None):
        """Reclassifying the labels from number of tracks to classes by subtracting 1

        Args:
            X (np.array): data array with shape (run_events, target_size,4)
            y (None): Defaults to None.

        Returns:
            (np.array): reclassified data labels
        """
        X_copy = X.copy() #don't want to change the labels from the original
        for i in range(len(X_copy)):
            if X_copy[i,-2,0] == 0:
                print("Event has 0 tracks")
                print("Event:",i," label:", X_copy[i,-2,0])
            else:
                X_copy[i,-2,0] -=1 

        return X_copy

transform(X, y=None)

Reclassifying the labels from number of tracks to classes by subtracting 1

Parameters:

Name Type Description Default
X array

data array with shape (run_events, target_size,4)

required
y None

Defaults to None.

None

Returns:

Type Description
array

reclassified data labels

Source code in scripts/ml_preprocessing_steps.py
def transform(self, X,y=None):
    """Reclassifying the labels from number of tracks to classes by subtracting 1

    Args:
        X (np.array): data array with shape (run_events, target_size,4)
        y (None): Defaults to None.

    Returns:
        (np.array): reclassified data labels
    """
    X_copy = X.copy() #don't want to change the labels from the original
    for i in range(len(X_copy)):
        if X_copy[i,-2,0] == 0:
            print("Event has 0 tracks")
            print("Event:",i," label:", X_copy[i,-2,0])
        else:
            X_copy[i,-2,0] -=1 

    return X_copy