Monotonic Constraints for Business Rules
In Lesson 4 you learned to read a learning curve and stop a booster before it overfits. That was about getting the SIZE of the fit right. This lesson is about a different worry, one that accuracy alone will never catch: getting the DIRECTION right.
Sam, who runs the bike-rental kiosks, now wants a pricing tool: type in tomorrow's rental price and it predicts how many bikes go out. Everyone at the kiosk knows one thing for certain: raise the price and you do not sell MORE bikes. Yet when Sam trains a booster on a season of noisy price experiments, the model does exactly that in a couple of spots. It predicts more rentals at $5.50 than at $5.00. The numbers fit the past, but no manager will trust a tool that says "charge more to sell more."
By the end of this lesson you will be able to:
- Say what a monotonic constraint is, in plain words and as a formula
- Recognize when a business needs one, and when forcing it would be a mistake
- Force a feature's effect to go one way in R, and read the result
- Weigh the small accuracy-for-trust trade that a constraint buys
Prerequisites: Lesson 1 (Gradient Boosting from Scratch: trees fit in sequence, the learning rate) and you can run R. The chart below is Sam's price experiment: each dot is one price he tested and the average bikes rented at it.
When accuracy is not enough
A model can be accurate and still be unusable. Sam's pricing tool will be read by staff who set prices every morning, and it has to obey a rule they already know in their bones: higher price, never more demand. A model that breaks that rule, even once, even when it scores well, gets switched off, because nobody trusts a tool that contradicts common sense.
This is not special to bikes. Across many fields there is a feature whose direction is fixed by domain knowledge or by law, and the model is expected to honor it:
| Feature | The rule the business needs | Direction |
|---|---|---|
| Applicant income | a higher income must never lower the approved loan amount | up |
| Insurance risk score | more risk must never lower the premium | up |
| Product price | a higher price must never raise predicted demand | down |
| Years of experience | more experience must never lower predicted pay | up |
A monotonic constraint is how you tell a model to obey one of these rules. It forces the prediction to move in only one direction as a chosen feature increases, no matter what wobble the training data happens to show.