Skip to content

pydvl.valuation.base

This module declares the abstract base classes for all valuation methods. A valuation method is any function that computes a value for each data point in a dataset.

Info

For information on data valuation, read the introduction.

ModelFreeValuation

ModelFreeValuation(references: Iterable[Dataset])

Bases: Valuation, ABC

TODO: Just a stub, probably should not inherit from Valuation.

Source code in src/pydvl/valuation/base.py
def __init__(self, references: Iterable[Dataset]):
    super().__init__()
    self.datasets = references

result property

The current valuation result (not a copy).

values

values(sort: bool = False) -> ValuationResult

Returns a copy of the valuation result.

The valuation must have been run with fit() before calling this method.

PARAMETER DESCRIPTION
sort

Whether to sort the valuation result by value before returning it.

TYPE: bool DEFAULT: False

Returns: The result of the valuation.

Source code in src/pydvl/valuation/base.py
@deprecated(
    target=None,
    deprecated_in="0.10.0",
    remove_in="0.11.0",
)
def values(self, sort: bool = False) -> ValuationResult:
    """Returns a copy of the valuation result.

    The valuation must have been run with `fit()` before calling this method.

    Args:
        sort: Whether to sort the valuation result by value before returning it.
    Returns:
        The result of the valuation.
    """
    if not self.is_fitted:
        raise NotFittedException(type(self))
    assert self._result is not None

    r = self._result.copy()
    if sort:
        r.sort(inplace=True)
    return r

Valuation

Valuation()

Bases: ABC

Abstract base class for all valuation methods.

Source code in src/pydvl/valuation/base.py
def __init__(self) -> None:
    self._result: ValuationResult | None = None

result property

The current valuation result (not a copy).

values

values(sort: bool = False) -> ValuationResult

Returns a copy of the valuation result.

The valuation must have been run with fit() before calling this method.

PARAMETER DESCRIPTION
sort

Whether to sort the valuation result by value before returning it.

TYPE: bool DEFAULT: False

Returns: The result of the valuation.

Source code in src/pydvl/valuation/base.py
@deprecated(
    target=None,
    deprecated_in="0.10.0",
    remove_in="0.11.0",
)
def values(self, sort: bool = False) -> ValuationResult:
    """Returns a copy of the valuation result.

    The valuation must have been run with `fit()` before calling this method.

    Args:
        sort: Whether to sort the valuation result by value before returning it.
    Returns:
        The result of the valuation.
    """
    if not self.is_fitted:
        raise NotFittedException(type(self))
    assert self._result is not None

    r = self._result.copy()
    if sort:
        r.sort(inplace=True)
    return r