mloss.org Calibrated AdaMEChttp://mloss.orgUpdates and additions to Calibrated AdaMECenSat, 08 Apr 2017 13:57:45 -0000Calibrated AdaMEC 1.0http://mloss.org/software/view/671/<html><p>AdaBoost is a successful and popular classification method, but it is not geared towards solving cost-sensitive classification problems, i.e. problems where the costs of different types of erroneous predictions are unequal. In our 2016 paper cited below, we reviewed all cost-sensitive variants of AdaBoost in the literature, along with our own adaptations. Below we provide code for the method that achieves the best empirical results without any need for parameter tuning, while satisfying all desirable theoretical properties. The method, 'Calibrated AdaMEC', is described in detail and motivated in the paper: </p> <p>Cost-sensitive boosting algorithms: Do we really need them? Nikolaos Nikolaou, Narayanan U. Edakunni, Meelis Kull, Peter A. Flach, Gavin Brown, Machine Learning, 104(2), pages 359-384, 2016. </p> <p>If you make use of the code found here, please cite the above paper. </p> <hr /> <p>Example of use: </p> <p>The following example showcases how to train and generate scores and predictions under Calibrated AdaMEC. The syntax follows the conventions of the AdaBoost implementation of scikit-learn. </p> <p>from sklearn.ensemble import AdaBoostClassifier </p> <p>from CalibratedAdaMEC import CalibratedAdaMECClassifier # Our calibrated AdaMEC implementation can be found here </p> <p>The code below assumes the user already split the binary classification data (classes denoted 0,1) into training and test sets, that they defined the cost of a false positive C_FP &amp; the cost of a false negative C_FN and selected the weak learner base_estimator and the ensemble size n_estimators </p> <p>Create and train an AdaBoostClassifier: </p> <p>AdaBoost = AdaBoostClassifier(base_estimator, n_estimators) </p> <p>AdaBoost = AdaBoost.fit(X_train, y_train)<br /> </p> <p>Create and train a CalibratedAdaMECClassifier --being cost-sensitive, it takes C_FP &amp; C_FN as arguments: </p> <p>CalAdaMEC = CalibratedAdaMECClassifier(base_estimator, n_estimators, C_FP, C_FN) </p> <p>CalAdaMEC = CalAdaMEC.fit(X_train, y_train) </p> <p>Produce AdaBoost &amp; Calibrated AdaMEC classifications: </p> <p>labels_AdaBoost = AdaBoost.predict(X_test) </p> <p>labels_CalibratedAdaMEC = CalAdaMEC.predict(X_test) </p> <p>Produce AdaBoost &amp; Calibrated AdaMEC scores (probability estimates) - keep only positive class scores: </p> <p>scores_AdaBoost = AdaBoost.predict_proba(X_test)[:,1] </p> <p>scores_CalibratedAdaMEC = CalAdaMEC.predict_proba(X_test)[:,1] </p> <hr /> <p>Examples of comparison to AdaBoost: </p> <p>1)Probability Estimation </p> <p>You can evaluate the two algorithms in terms of probability estimation using the Brier score, or the log-loss, found e.g. in the metrics module of scikit-learn. You will see that Calibrated AdaMEC achieves lower scores for both (better probability estimation). </p> <p>from sklearn import metrics </p> <p>brier_score_AdaBoost = metrics.brier_score_loss(y_test, scores_AdaBoost) </p> <p>brier_score_CalibratedAdaMEC = metrics.brier_score_loss(y_test, scores_CalibratedAdaMEC) </p> <p>log_loss_AdaBoost = metrics.log_loss(y_test, scores_AdaBoost) </p> <p>log_loss_CalibratedAdaMEC = metrics.log_loss(y_test, scores_CalibratedAdaMEC) </p> <p>2)Cost-sensitive Classification </p> <p>You can evaluate the cost-sensitive behaviour of the classifications produced by the two algorithms in terms of total cost sensitive loss (empirical risk),as shown below. In expectation, the misclassification cost should be lower for Calibrated AdaMEC on asymmetric problems (the greater the skew, the greater the performance gain of Calibrated AdaMEC over AdaBoost). </p> <p>from sklearn import metrics </p> <p>Pos = sum(y_train[np.where(y_train == 1)]) #Number of positive training examples </p> <p>Neg = len(y_train) - Pos #Number of negative training examples </p> <p>skew = C_FP*Neg / (C_FN<em>Pos + C_FP</em>Neg) #Skew (combined asymmetry due to both cost and class imbalance) </p> <p>conf_mat_AdaBoost = metrics.confusion_matrix(y_test, labels_AdaBoost)#Confusion matrix </p> <p>cost_AdaBoost = conf_mat_AdaBoost[0,1]<em>skew + conf_mat_AdaBoost[1,0]</em>(1-skew)#Skew-Sensitive Cost </p> <p>conf_mat_CalibratedAdaMEC = metrics.confusion_matrix(y_test, labels_CalibratedAdaMEC)#Confusion matrix </p> <p>cost_CalibratedAdaMEC = conf_mat_CalibratedAdaMEC[0,1]<em>skew + conf_mat_CalibratedAdaMEC[1,0]</em>(1-skew)#Skew-Sensitive Cost </p> <hr /> <p>Looking For a more flexible implementation? </p> <p>The code given here is using Platt scaling (logistic sigmoid calibration) and a 50%-50% train-calibration split. The user is also restricted to using the discrete version of AdaBoost. </p> <p>Go to https://github.com/nnikolaou/Cost-sensitive-Boosting-Tutorial for an extended ipython tutorial, providing a summary of the paper and interactive code allowing you to reproduce our experiments and run your own ones, every aspect of which (problem setup, calibration options, ensemble parameters, base learner parameters, evaluation measures) can be modified. </p></html>Nikolaos Nikolaou, Gavin BrownSat, 08 Apr 2017 13:57:45 -0000http://mloss.org/software/rss/comments/671http://mloss.org/software/view/671/ensemblesadaboostboostingensemble of classifiersensemble methodsensemble learningensemble modelcalibrationclass imbalancecost sensitiveminimum expected costrisk minimization