mapie/predict-function-returns-labels
| Rule | predict-function-returns-labels |
|---|---|
| Pack | MAPIE |
| Severity | error |
| Fix | unsafe, with xpd check --fix --unsafe-fixes |
| Library versions | every version |
BinaryClassificationController needs a function that returns class probabilities, and predict returns labels, so calibrate raises IndexError. Pass model.predict_proba.
controller = BinaryClassificationController(model.predict, "precision", target_level=0.8)controller = BinaryClassificationController(model.predict_proba, "precision", target_level=0.8)What the rule reports
Section titled “What the rule reports”The rule reports BinaryClassificationController with model.predict as its predict_function.
How to fix it
Section titled “How to fix it”xpd check --fix --unsafe-fixes applies the fixes of this rule. Check the result, because an unsafe fix can change what the code does.
The unsafe fix writes model.predict_proba.
With model.predict, calibrate raised IndexError, "Error when calling the predict_function",
because the controller reads the probability of the positive class from the second column.
MultiLabelClassificationController ran with predict, so the rule leaves it alone.
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
BinaryClassificationController needs a function that returns the probability of each class, and $M.predict returns labels, so calibrate raises IndexError. Pass $M.predict_proba.Browse the other rules of the MAPIE pack.