def reshapeParams(hyperparams, reshaper):
    """
    A utility function that takes a dictionary of transformations for valid hyperparameters
    and filters out invalid params

    Testing the function:
    print reshapeParams({'regParam': 'invalid', 'elasticNetParam': 0.1, 'maxDepth': 0.1}, {'regParam': float, 'elasticNetParam': float, 'threshold': float})
    # Expect: {'elasticNetParam': 0.1}
    :param hyperparams: the dirty dictionary
    :param reshaper: the transformations
    :return: the clean dictionary
    """
    d = {}
    for k, v in hyperparams.items():
        if reshaper.has_key(k):
            f = reshaper[k]
            if isinstance(v, str):
                if v.replace('.', '', 1).isdigit():
                    d[k] = f(v)
                else:
                    continue
            elif isinstance(v, float):
                d[k] = f(v)
            elif isinstance(v, int):
                d[k] = f(v)
            else:
                continue
        else:
            continue
    return d
