Empulse#

Not every mistake costs the same.

Accuracy, F1 and AUC treat a false positive and a false negative as equally bad. Your business does not. Flagging a loyal customer as a churner wastes a discount; missing a real churner loses their entire lifetime value. A model tuned for accuracy quietly optimises the wrong thing.

Empulse lets you write down what each outcome is actually worth, then use that same definition to evaluate models, train them, and set their decision threshold — as a normal scikit-learn estimator.

from empulse.metrics import Cost, CostMatrix, Metric
from empulse.models import CSBoostClassifier
from sklearn.datasets import make_classification

X, y = make_classification(n_samples=500, random_state=42)

# 1. Write down what each mistake costs
cost_matrix = (
    CostMatrix()
    .add_fp_cost('wasted_discount')
    .add_fn_cost('lost_customer')
    .set_default(wasted_discount=5, lost_customer=100)
)

# 2. Turn it into a metric
expected_cost = Metric(cost_matrix, Cost())

# 3. Train a model that optimises it directly
model = CSBoostClassifier(loss=expected_cost).fit(X, y)

cost_per_customer = expected_cost(y, model.predict_proba(X)[:, 1])
Getting Started

Install Empulse and get a working cost-sensitive model in five minutes. Start here if you are new.

Getting Started
Tutorial

A complete worked example on a real churn dataset, from a cost-blind baseline to a deployed, profit-optimised pipeline.

Tutorial
User Guide

Task-oriented guides for each model, metric, sampler and dataset. Go here once you know what you need.

User Guide
API Reference

The full class and function reference, with every parameter documented.

API Reference

What can you do with Empulse?#

Measure profit, not accuracy

Ready-made metrics for churn, acquisition and credit scoring, or define your own.

Train on your cost matrix

Logistic regression, gradient boosting, trees and ensembles that optimise business value during training.

Set the right threshold

Pick the cut-off that maximises profit instead of defaulting to 0.5.

Per-customer costs

Costs that differ per row are routed through pipelines and cross-validation automatically.

Handle noisy costs

RobustCSClassifier detects and corrects outliers in instance-dependent costs.

Reweight the data instead

Cost-proportionate sampling and bias mitigation make any estimator cost-sensitive.

Everything follows scikit-learn conventions, so Empulse estimators drop into Pipeline, GridSearchCV and cross_val_score unchanged, and every metric can be wrapped with make_scorer.