Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Custom targets, filters, and model classes

The fitted target stores the row information needed by a measure. Filters control eligibility. A likelihood model encapsulates a fitting procedure. Keep these roles separate so that a new component can reuse the rest of the workflow.

A weighted numeric target

As an example, suppose rows have nonnegative importance weights and we want a weighted mean shift. This is a custom statistic; the built-in numeric measures do not silently apply a weight column.

Loading...

BaseTarget.fit records attributes_ and the number of rows. Both value and weight columns are thereby excluded from descriptions. Inherited refit constructs the same class and calls fit with these attributes. A configurable constructor or additional non-attribute fitting arguments require a corresponding refit implementation or _fit_arguments specification.

Original reference mean: 3.0
Refitted reference mean: 3.2

Targets must be refitted whenever the data changes, including row order changes. Equal lengths alone do not make targets interchangeable. A custom target gets the common table statistics (size, relative_size, depth); the built-in table helper does not infer custom model parameters automatically.

Custom constraints

A result may be required to mention a feature or to satisfy an application condition. Consider a filter requiring the descriptor group:

False
True

The empty description fails, but adding group=A can pass. Therefore this is a result-only constraint. By contrast, “at least ten covered rows” is safe for pruning. A custom class can subclass Filter and provide is_satisfied_many if it can decide from batch statistics; the simple callable wrapper is scalar.

A pluggable likelihood model

To illustrate the model protocol, fit a univariate Gaussian with known unit variance and an estimated mean. Only one free parameter is fitted. This implements the normal log-density directly; it is intentionally simpler than the built-in polynomial regression model.

Loading...

The target prepares a copy of the model on its data. fit(mask) must return None for an undefined fit; zero is a legitimate parameter value. Return one log-likelihood per requested row, not the sum. The likelihood quality function performs the required aggregation and compares fits. describe supplies names for parameter columns in result tables.

A likelihood-ratio interpretation additionally needs the chosen model and its regularity assumptions to make sense. The number of free parameters is a property of the fitted family, not merely the length of an arbitrary return object.

Optional: a valuation domain for GP-growth

If a model can be recovered from condensed statistics, a valuation domain can make those statistics available to GP-growth Lemmerich et al., 2012. A numeric mean needs only count and sum:

Loading...

The default domain aggregation and subtraction are vector addition and subtraction. Its default distance is absolute model difference, so this example scores subgroup-versus-complement mean distance without a size factor. An associative aggregation operation and a correct model projector are essential; arbitrary non-associative state cannot be condensed in the same way.

Experiment. Extend the mean domain with a sum-of-squares component and derive a variance projector. Consider numerical cancellation before using the naive formula on values with a very large offset.

References
  1. Lemmerich, F., Becker, M., & Atzmueller, M. (2012). Generic Pattern Trees for Exhaustive Exceptional Model Mining. Machine Learning and Knowledge Discovery in Databases.