import gc
import logging


def train_classifier(classifier, X_train, y_train):
    """
    Fits a classifier on the given data.
    :param classifier: classifier
    :param X_train: training attribute values
    :param y_train: training classes
    :return: a fitted model
    """
    gc.collect()
    logging.info("Training...")
    # Experimental - to reduce memory consumption
    # y_train, y_train_filename = mmap(y_train, 'y_train')
    classifier.fit(X_train, y_train)
    # Experimental - to reduce memory consumption
    # X_train, X_train_filename = mmap(X_train, 'X_train')
    gc.collect()

    return classifier