CardiovascularDisease/CVD/preprocessor.py
def scaler(X_train: pd.DataFrame, X_test: pd.DataFrame, *, cat_feats=None, num_feats=None):
    """
    Choose between scaling the data using the StandardScaler or heterogeneous scaling of features.
    For heterogeneous scaling, the categorical and numerical features must be specified.
    Then, apply:

    - min_max scaling (from -1 to 1) for categoricals
      (to avoid non-symmetric scaling about zero due to category frequencies in dataset)
    - standard scaling for numerical features
    """

    if num_feats is None:
        num_feats = []
    if cat_feats is None:
        cat_feats = []

    X_train_scaled = pd.DataFrame()
    X_test_scaled = pd.DataFrame()

    std_scaler = StandardScaler()

    if len(cat_feats) == 0:
        X_train_scaled = std_scaler.fit_transform(X_train)
        X_test_scaled = std_scaler.transform(X_test)
    else:
        mm_scaler = MinMaxScaler(feature_range=(-1, 1))

        for cfeat in cat_feats:
            X_train_scaled[cfeat] = mm_scaler.fit_transform(np.array(X_train[cfeat]).reshape(-1, 1)).squeeze()
            X_test_scaled[cfeat] = mm_scaler.transform(np.array(X_test[cfeat]).reshape(-1, 1)).squeeze()

        for nfeat in num_feats:
            X_train_scaled[nfeat] = std_scaler.fit_transform(np.array(X_train[nfeat]).reshape(-1, 1)).squeeze()
            X_test_scaled[nfeat] = std_scaler.transform(np.array(X_test[nfeat]).reshape(-1, 1)).squeeze()

    return X_train_scaled, X_test_scaled

    Choose between scaling the data using the StandardScaler or heterogeneous scaling of features.
    For heterogeneous scaling, the categorical and numerical features must be specified.
    Then, apply:

    - min_max scaling (from -1 to 1) for categoricals
      (to avoid non-symmetric scaling about zero due to category frequencies in dataset)
    - standard scaling for numerical features
    
Choose between scaling the data using the StandardScaler or heterogeneous scaling of features.
For heterogeneous scaling, the categorical and numerical features must be specified.
Then, apply.

min_max scaling (from -1 to 1) for categoricals
(to avoid non-symmetric scaling about zero due to category frequencies in dataset)
standard scaling for numerical features
Choose between scaling the data using the StandardScaler or heterogeneous scaling of features . For heterogeneous scaling the categorical and numerical features must be specified . Then apply . min_max scaling ( from - 1 to 1 ) for categoricals ( to avoid non - symmetric scaling about zero due to category frequencies in dataset ) standard scaling for numerical features
def scaler(X_train: pd.DataFrame, X_test: pd.DataFrame, *, cat_feats=None, num_feats=None):
    if num_feats is None:
        num_feats = []
    if cat_feats is None:
        cat_feats = []
    X_train_scaled = pd.DataFrame()
    X_test_scaled = pd.DataFrame()
    std_scaler = StandardScaler()
    if len(cat_feats) == 0:
        X_train_scaled = std_scaler.fit_transform(X_train)
        X_test_scaled = std_scaler.transform(X_test)
    else:
        mm_scaler = MinMaxScaler(feature_range=(-1, 1))
        for cfeat in cat_feats:
            X_train_scaled[cfeat] = mm_scaler.fit_transform(np.array(X_train[cfeat]).reshape(-1, 1)).squeeze()
            X_test_scaled[cfeat] = mm_scaler.transform(np.array(X_test[cfeat]).reshape(-1, 1)).squeeze()
        for nfeat in num_feats:
            X_train_scaled[nfeat] = std_scaler.fit_transform(np.array(X_train[nfeat]).reshape(-1, 1)).squeeze()
            X_test_scaled[nfeat] = std_scaler.transform(np.array(X_test[nfeat]).reshape(-1, 1)).squeeze()
    return X_train_scaled, X_test_scaled
def scaler ( X_train : pd . DataFrame , X_test : pd . DataFrame , * , cat_feats = None , num_feats = None ) : if num_feats is None : num_feats = [ ] if cat_feats is None : cat_feats = [ ] X_train_scaled = pd . DataFrame ( ) X_test_scaled = pd . DataFrame ( ) std_scaler = StandardScaler ( ) if len ( cat_feats ) == 0 : X_train_scaled = std_scaler . fit_transform ( X_train ) X_test_scaled = std_scaler . transform ( X_test ) else : mm_scaler = MinMaxScaler ( feature_range = ( - 1 , 1 ) ) for cfeat in cat_feats : X_train_scaled [ cfeat ] = mm_scaler . fit_transform ( np . array ( X_train [ cfeat ] ) . reshape ( - 1 , 1 ) ) . squeeze ( ) X_test_scaled [ cfeat ] = mm_scaler . transform ( np . array ( X_test [ cfeat ] ) . reshape ( - 1 , 1 ) ) . squeeze ( ) for nfeat in num_feats : X_train_scaled [ nfeat ] = std_scaler . fit_transform ( np . array ( X_train [ nfeat ] ) . reshape ( - 1 , 1 ) ) . squeeze ( ) X_test_scaled [ nfeat ] = std_scaler . transform ( np . array ( X_test [ nfeat ] ) . reshape ( - 1 , 1 ) ) . squeeze ( ) return X_train_scaled , X_test_scaled
Choose between scaling the data using the StandardScaler or heterogeneous scaling of features.
Choose between scaling the data using the StandardScaler or heterogeneous scaling of features .
"""
    Choose between scaling the data using the StandardScaler or heterogeneous scaling of features.
    For heterogeneous scaling, the categorical and numerical features must be specified.
    Then, apply:

    - min_max scaling (from -1 to 1) for categoricals
      (to avoid non-symmetric scaling about zero due to category frequencies in dataset)
    - standard scaling for numerical features
    """
X_train
pd.DataFrame
X_test
pd.DataFrame
cat_feats
num_feats