import inspect


def check_params(
    func,
    return_invalids=False,
    **kwargs,
):
    """Return only valid parameters for a function a class from named parameters.

    Parameters
    ----------
    func : callable
        n_features-dimensional points.
    **kwargs :
        Arbitrary keyword arguments.
    return_invalids : bool (default: False)
        If True, return both the valid and invalid arguments in a list.

    Returns
    -------
    new_kwargs :
        Only valid keyword arguments w.r. of func.
    kwargs : (optional)
        Only invalid keyword arguments w.r. of func. (only if return_invalids is True)

    """
    params = list(inspect.signature(func).parameters.keys())
    new_kwargs = dict()
    keys = kwargs.keys()
    for key in list(keys):
        if key in params:
            new_kwargs[key] = kwargs[key]
            del kwargs[key]

    if return_invalids:
        return new_kwargs, kwargs
    else:
        return new_kwargs