src/models/train_model.py
def preproc(X_train, X_val, cat_cols, cols_to_keep):
    """ Preprocesses training and validation sets ready for the neural network training.

    For each categorical column, the function remaps the values to the integer values and adds a one-dimensional
    numpy array of with mapped values to the output list. Other columns are treated as numeric and added as numpy array
    as the last element of the output list.

    :param X_train: training set, numpy array.
    :param X_val: validation set numpy array.
    :param cat_cols: names of the categorical columns
    :param cols_to_keep: names of columns selected for the model training.
    :return: a list with preprocessed data ready for an entity embedding neural network model.
    """
    other_cols = [not c in cat_cols for c in cols_to_keep]
    input_list_train = []
    input_list_val = []

    # the cols to be embedded: rescaling to range [0, # values)
    for c in cat_cols:
        el_index = cols_to_keep.index(c)
        raw_vals = np.unique(np.concatenate((X_train, X_val), axis=0)[:, el_index])
        raw_vals.sort()
        val_map = {}
        for i in range(len(raw_vals)):
            val_map[raw_vals[i]] = i
        input_list_train.append(np.vectorize(val_map.get)(X_train[:, el_index]))
        input_list_val.append(np.vectorize(val_map.get)(X_val[:, el_index]))

    # the rest of the columns
    input_list_train.append(X_train[:, other_cols])
    input_list_val.append(X_val[:, other_cols])

    return input_list_train, input_list_val
 Preprocesses training and validation sets ready for the neural network training.

    For each categorical column, the function remaps the values to the integer values and adds a one-dimensional
    numpy array of with mapped values to the output list. Other columns are treated as numeric and added as numpy array
    as the last element of the output list.

    :param X_train: training set, numpy array.
    :param X_val: validation set numpy array.
    :param cat_cols: names of the categorical columns
    :param cols_to_keep: names of columns selected for the model training.
    :return: a list with preprocessed data ready for an entity embedding neural network model.
    
Preprocesses training and validation sets ready for the neural network training.
For each categorical column, the function remaps the values to the integer values and adds a one-dimensional
numpy array of with mapped values to the output list. Other columns are treated as numeric and added as numpy array
as the last element of the output list.
Preprocesses training and validation sets ready for the neural network training . For each categorical column the function remaps the values to the integer values and adds a one - dimensional numpy array of with mapped values to the output list . Other columns are treated as numeric and added as numpy array as the last element of the output list .
def preproc(X_train, X_val, cat_cols, cols_to_keep):
    other_cols = [not c in cat_cols for c in cols_to_keep]
    input_list_train = []
    input_list_val = []
    for c in cat_cols:
        el_index = cols_to_keep.index(c)
        raw_vals = np.unique(np.concatenate((X_train, X_val), axis=0)[:, el_index])
        raw_vals.sort()
        val_map = {}
        for i in range(len(raw_vals)):
            val_map[raw_vals[i]] = i
        input_list_train.append(np.vectorize(val_map.get)(X_train[:, el_index]))
        input_list_val.append(np.vectorize(val_map.get)(X_val[:, el_index]))
    input_list_train.append(X_train[:, other_cols])
    input_list_val.append(X_val[:, other_cols])
    return input_list_train, input_list_val
def preproc ( X_train , X_val , cat_cols , cols_to_keep ) : other_cols = [ not c in cat_cols for c in cols_to_keep ] input_list_train = [ ] input_list_val = [ ] for c in cat_cols : el_index = cols_to_keep . index ( c ) raw_vals = np . unique ( np . concatenate ( ( X_train , X_val ) , axis = 0 ) [ : , el_index ] ) raw_vals . sort ( ) val_map = { } for i in range ( len ( raw_vals ) ) : val_map [ raw_vals [ i ] ] = i input_list_train . append ( np . vectorize ( val_map . get ) ( X_train [ : , el_index ] ) ) input_list_val . append ( np . vectorize ( val_map . get ) ( X_val [ : , el_index ] ) ) input_list_train . append ( X_train [ : , other_cols ] ) input_list_val . append ( X_val [ : , other_cols ] ) return input_list_train , input_list_val
Preprocesses training and validation sets ready for the neural network training.
Preprocesses training and validation sets ready for the neural network training .
""" Preprocesses training and validation sets ready for the neural network training.

    For each categorical column, the function remaps the values to the integer values and adds a one-dimensional
    numpy array of with mapped values to the output list. Other columns are treated as numeric and added as numpy array
    as the last element of the output list.

    :param X_train: training set, numpy array.
    :param X_val: validation set numpy array.
    :param cat_cols: names of the categorical columns
    :param cols_to_keep: names of columns selected for the model training.
    :return: a list with preprocessed data ready for an entity embedding neural network model.
    """ # the cols to be embedded: rescaling to range [0, # values) # the rest of the columns
a list with preprocessed data ready for an entity embedding neural network model.
a list with preprocessed data ready for an entity embedding neural network model .
X_train
training set, numpy array.
training set numpy array .
X_val
validation set numpy array.
validation set numpy array .
cat_cols
names of the categorical columns
names of the categorical columns
cols_to_keep
names of columns selected for the model training.
names of columns selected for the model training .