sklift.metrics.make_uplift_scorer
- sklift.metrics.metrics.make_uplift_scorer(metric_name, treatment, **kwargs)[source]
Make uplift scorer which can be used with the same API as
sklearn.metrics.make_scorer
.- Parameters
metric_name (string) – Name of desirable uplift metric. Raise ValueError if invalid.
treatment (pandas.Series) – A Series from original DataFrame which contains original index and treatment group column.
kwargs (additional arguments) – Additional parameters to be passed to metric func. For example: negative_effect, strategy, k or somtething else.
- Returns
An uplift scorer with passed treatment variable (and kwargs, optionally) that returns a scalar score.
- Return type
scorer (callable)
- Raises
ValueError – if metric_name does not present in metrics list.
ValueError – if treatment is not a pandas Series.
Example:
from sklearn.model_selection import cross_validate from sklift.metrics import make_uplift_scorer # define X_cv, y_cv, trmnt_cv and estimator # Use make_uplift_scorer to initialize new `sklearn.metrics.make_scorer` object qini_scorer = make_uplift_scorer("qini_auc_score", trmnt_cv) # or pass additional parameters if necessary uplift50_scorer = make_uplift_scorer("uplift_at_k", trmnt_cv, strategy='overall', k=0.5) # Use this object in model selection functions cross_validate(estimator, X=X_cv, y=y_cv, fit_params={'treatment': trmnt_cv} scoring=qini_scorer, )