ddl.validation.check_density

ddl.validation.check_density(density, random_state=0)[source]

Check that an estimator implements density methods correctly.

First, check that the estimator implements sklearn’s estimator interface via sklearn.utils.estimator_checks.check_estimator. Then, check for all of the following methods, and possibly check their basic functionality. Some methods will raise errors and others will issue warnings.

Required methods (error if fails or does not exist):

  • fit

Optional methods primary (warn if does not exist, error if fails):

  • sample
  • score_samples

Optional methods secondary (warn if does not exist, warn if fails):

  • score (mixin)
  • get_support (required to pass tests if support is not real-valued unbounded)
Parameters:
density : estimator

Density estimator to check.

random_state : int, RandomState instance or None, optional (default=0)

Note that random_state defaults to 0 so that checks are reproducible by default.

If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by numpy.random.

See also

check_destructor

Notes

The score method must be equal to the average of score_samples for consistency. Note that some sklearn density estimators such as sklearn.mixture.GaussianMixture return the total log probability instead of the average log probability. Thus, these estimators need to be subclassed and their score method overwritten.