9.1. Composable Quantifiers#

Compose quantifiers build prevalence estimators by combining a representation, a loss function, and a solver. This makes it easy to swap components when you want to experiment with alternative representations or objectives.

9.1.1. Key classes#

9.1.2. Linear compose example#

from sklearn.linear_model import LogisticRegression
from mlquantify.compose import LinearComposeQuantifier
from mlquantify.representations import HistogramRepresentation

representation = HistogramRepresentation(bins=(10,))
q = LinearComposeQuantifier(
    representation=representation,
    estimator=LogisticRegression(),
    loss="least_squares",
)

q.fit(X_train, y_train)
prevalence = q.predict(X_test)

9.1.3. Likelihood compose example#

from sklearn.linear_model import LogisticRegression
from mlquantify.compose import LikelihoodComposeQuantifier

q = LikelihoodComposeQuantifier(
    estimator=LogisticRegression(),
    tau_0=0.1,
    tau_1=0.0,
)

q.fit(X_train, y_train)
prevalence = q.predict(X_test)