@interactive
def train_model(model, data_filename, model_filename=None,
                random_state=None):
    from sklearn.externals import joblib

    # Memory map the data
    X, y, sample_weight = joblib.load(data_filename, mmap_mode='r')

    # Train the model
    model.set_params(random_state=random_state)
    if sample_weight is not None:
        model.fit(X, y, sample_weight=sample_weight)
    else:
        model.fit(X, y)

    # Clean the random_state attributes to reduce the amount
    # of useless numpy arrays that will be created on the
    # filesystem (fixed upstream in sklearn 0.15-git)
    for estimator in model.estimators_:
        if (hasattr(estimator, 'tree_')
                and hasattr(estimator.tree_, 'random_state')):
            estimator.tree_.random_state = 0

    # Save the model back to the FS as it can be large
    if model_filename is not None:
        joblib.dump(model, model_filename)
        return model_filename

    # TODO: add support for cloud blob stores as an alternative to
    # filesystems.

    # Return the tree back to the caller if (useful if the drive)
    return model
dataset/ETHPy150Open pydata/pyrallel/pyrallel/ensemble.py/train_model/original