ProfLogitClassifier#
- class empulse.models.ProfLogitClassifier(loss, C=1.0, fit_intercept=True, soft_threshold=False, l1_ratio=1.0, optimize_fn=None, optimizer_params=None, n_jobs=None)[source]#
Profit-driven logistic regression classifier.
Maximizing empirical (Expected) maximum profit score by optimizing the regression coefficients of the logistic model through a Real-coded Genetic Algorithm (RGA).
Read more in the User Guide.
- Parameters:
- lossCallable or
empulse.metrics.Metric Loss function to optimize.
If
Callableit should have a signatureloss(y_true, y_score).If :class`~empulse.metrics.Metric`, metric parameters are passed as
loss_paramsto thefitmethod.
By default, loss function is maximized, customize behaviour in optimize_fn. If the loss function in an instance of
Metricthen the optimization direction is automatically determined.- Cfloat, default=1.0
Inverse of regularization strength; must be a positive
float. Like in support vector machines, smaller values specify stronger regularization.- fit_interceptbool, default=True
Specifies if a constant (a.k.a. bias or intercept) should be added to the decision function.
- soft_thresholdbool, default=False
If
True, apply soft-thresholding to the regression coefficients.- l1_ratiofloat, default=1.0
The ElasticNet mixing parameter, with
0 <= l1_ratio <= 1. Forl1_ratio = 0the penalty is a L2 penalty. Forl1_ratio = 1it is a L1 penalty. For0 < l1_ratio < 1, the penalty is a combination of L1 and L2.- optimize_fnCallable, optional
Optimization algorithm. Should be a Callable with signature
optimize(objective, X). See Profit-Driven Logistic Regression (ProfLogit) for more information.- optimizer_paramsdict[str, Any], optional
Additional keyword arguments passed to optimize_fn.
By default, the optimizer is a Real-coded Genetic Algorithm (RGA) with the following parameters:
max_iterint, default=1000Maximum number of iterations.
patienceint, default=250Number of iterations with no improvement to wait before stopping the optimization.
tolerancefloat, default=1e-4Relative tolerance to declare convergence.
boundstuple[float, float], default=(-5, 5)Lower and upper bounds for the regression coefficients.
all other parameters are passed to the
Generationinitializer.
- n_jobsint, optional
Number of parallel jobs to run.
Nonemeans 1 unless in ajoblib.parallel_backendcontext.-1means using all processors.
- lossCallable or
- Attributes:
- classes_numpy.ndarray
Unique classes in the target found during fit.
- result_
scipy.optimize.OptimizeResult Optimization result.
- coef_numpy.ndarray
Coefficients of the logit model.
- intercept_float
Intercept of the logit model. Only available when
fit_intercept=True.
References
[1]Stripling, E., vanden Broucke, S., Antonio, K., Baesens, B. and Snoeck, M. (2017). Profit Maximizing Logistic Model for Customer Churn Prediction Using Genetic Algorithms. Swarm and Evolutionary Computation.
[2]Stripling, E., vanden Broucke, S., Antonio, K., Baesens, B. and Snoeck, M. (2015). Profit Maximizing Logistic Regression Modeling for Customer Churn Prediction. IEEE International Conference on Data Science and Advanced Analytics (DSAA) (pp. 1–10). Paris, France.
Examples
from empulse.metrics import mpc_score from empulse.models import ProfLogitClassifier from sklearn.datasets import make_classification X, y = make_classification() model = ProfLogitClassifier(loss=mpc_score, C=0.1, l1_ratio=0.5) model.fit(X, y, clv=200, incentive_cost=10)
- fit(X, y, **loss_params)[source]#
Fit ProfLogit model.
- Parameters:
- X2D array-like, shape=(n_samples, n_features)
Training data.
- y1D array-like, shape=(n_samples,)
Target values.
- loss_paramsdict
Additional keyword arguments passed to loss.
- Returns:
- selfProfLogitClassifier
Fitted ProfLogit model.
- get_metadata_routing()#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routingMetadataRequest
A
MetadataRequestencapsulating routing information.
- get_params(deep=True)#
Get parameters for this estimator.
- Parameters:
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
- paramsdict
Parameter names mapped to their values.
- predict(X)#
Compute predicted labels.
- Parameters:
- X2D array-like, shape=(n_samples, n_dim)
Features.
- Returns:
- y_pred1D numpy.ndarray, shape=(n_samples,)
Predicted labels.
- predict_proba(X)#
Compute predicted probabilities.
- Parameters:
- X2D array-like, shape=(n_samples, n_features)
Features.
- Returns:
- y_pred2D numpy.ndarray, shape=(n_samples, 2)
Predicted probabilities.
- score(X, y, sample_weight=None)#
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
Test samples.
- yarray-like of shape (n_samples,) or (n_samples, n_outputs)
True labels for X.
- sample_weightarray-like of shape (n_samples,), default=None
Sample weights.
- Returns:
- scorefloat
Mean accuracy of
self.predict(X)w.r.t. y.
- set_params(**params)#
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline). The latter have parameters of the form<component>__<parameter>so that it’s possible to update each component of a nested object.- Parameters:
- **paramsdict
Estimator parameters.
- Returns:
- selfestimator instance
Estimator instance.
- set_score_request(*, sample_weight='$UNCHANGED$')#
Request metadata passed to the
scoremethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline. Otherwise it has no effect.- Parameters:
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
- Returns:
- selfobject
The updated object.