Day 20: Two-Feature Decision Surfaces from Rule Expressions π―π
See how simple rule expressions create complex decision boundaries. Visualize the geometric partitions that emerge from threshold-based rules in feature space.
Decision surfaces transform abstract rule expressions into visual partitions of feature space, revealing how thresholds create classification boundaries.
When you combine multiple feature thresholds with AND/OR logic, you create geometric partitions in feature space. Understanding these decision surfaces is crucial for interpreting rule-based systems and optimizing thresholds.
π‘ Note: This article uses technical terms and abbreviations. For definitions, check out the Key Terms & Glossary page.
The Power of Visualizing Rules ποΈ
Scenario: You're building a risk scoring system with two features:
- Feature X: Transaction amount
- Feature Y: Account age
Rule: IF (amount β₯ $1000) AND (age β₯ 30 days) THEN High Risk
Question: What does this rule look like in feature space? π€
Answer: A rectangular region! The rule creates a decision surface that partitions the 2D space into "High Risk" and "Low Risk" regions.
Visual Example:
Visualizing decision surfaces transforms abstract rules into concrete geometric partitions, making it easier to understand and optimize rule-based systems.
Half-Spaces: The Building Blocks π§±
What is a Half-Space?
A half-space is the region on one side of a line (in 2D) or plane (in 3D).
In 2D:
x β₯ acreates a vertical half-space (everything to the right of x = a)y β₯ bcreates a horizontal half-space (everything above y = b)
Visual Example:
Combining Half-Spaces
When you combine half-spaces with AND or OR logic, you create more complex regions:
AND (Intersection):
Rule: x β₯ a AND y β₯ b
Result: The intersection of two half-spaces
β A rectangular region (quadrant)
OR (Union):
Rule: x β₯ a OR y β₯ b
Result: The union of two half-spaces
β An L-shaped region
Visual Example:
Orthogonal Cut Lines: Creating Quadrants βοΈ
What are Orthogonal Cut Lines?
Orthogonal cut lines are perpendicular lines that divide feature space into regions. In 2D, they're typically:
- Vertical lines:
x = threshold_x - Horizontal lines:
y = threshold_y
Example:
Thresholds:
- x_threshold = 1000
- y_threshold = 30
Cut lines:
- Vertical: x = 1000
- Horizontal: y = 30
Result: Four quadrants:
- Q1 (Top-Right): x β₯ 1000 AND y β₯ 30 β High Risk β
- Q2 (Top-Left): x < 1000 AND y β₯ 30 β Low Risk
- Q3 (Bottom-Left): x < 1000 AND y < 30 β Low Risk
- Q4 (Bottom-Right): x β₯ 1000 AND y < 30 β Low Risk
Visual Example:
Decision Surfaces from Rule Expressions π¨
Simple AND Rule
Rule: IF (x β₯ a) AND (y β₯ b) THEN Positive
Decision Surface:
- Creates a rectangular region in the top-right quadrant
- All points in this region are classified as "Positive"
- All other points are classified as "Negative"
Visual Example:
Simple OR Rule
Rule: IF (x β₯ a) OR (y β₯ b) THEN Positive
Decision Surface:
- Creates an L-shaped region
- Covers three quadrants (top-right, top-left, bottom-right)
- Only bottom-left quadrant is "Negative"
Visual Example:
Complex Rules
Rule: IF (x β₯ a AND y β₯ b) OR (x β₯ c AND y β₯ d) THEN Positive
Decision Surface:
- Creates multiple rectangular regions
- Union of two rectangular regions
- More complex partition of feature space
Visual Example:
Decision surfaces act like fortresses, creating clear boundaries that protect and organize your feature space into meaningful regions.
Lattice Ordering: Understanding Threshold Relationships π
Connection to Day 1: Lattice ordering helps us understand how threshold changes affect decision surfaces.
What is Lattice Ordering?
In a lattice, we can compare rules based on their "strictness":
- Rule A is stricter than Rule B if Rule A's region is a subset of Rule B's region
- Rule A is looser than Rule B if Rule A's region is a superset of Rule B's region
Example:
Rule 1: x β₯ 1000 AND y β₯ 30 (stricter)
Rule 2: x β₯ 500 AND y β₯ 20 (looser)
Rule 1's region is inside Rule 2's region
β Rule 1 is stricter than Rule 2
Visual Example:
Threshold Changes and Lattice Ordering
Increasing a threshold makes the rule stricter:
- The decision region shrinks
- Fewer points are classified as positive
- Higher precision, lower recall
Decreasing a threshold makes the rule looser:
- The decision region expands
- More points are classified as positive
- Lower precision, higher recall
Real-World Application: ATL/BTL Shading π―
What is ATL/BTL?
ATL (Above The Line): Points that satisfy the rule (classified as positive) BTL (Below The Line): Points that don't satisfy the rule (classified as negative)
create_scatter_plot Function
The create_scatter_plot function visualizes decision surfaces by:
- Plotting data points in 2D feature space
- Drawing threshold lines (cut lines)
- Shading regions based on rule satisfaction
- Color-coding points as ATL (positive) or BTL (negative)
Visual Example:
Code Concept:
Show code (14 lines)
def create_scatter_plot(x_data, y_data, x_threshold, y_threshold, rule_type='AND'):
"""
Create scatter plot with decision surface shading
Parameters:
- x_data, y_data: Feature values
- x_threshold, y_threshold: Rule thresholds
- rule_type: 'AND' or 'OR'
"""
# Plot data points
# Draw threshold lines
# Shade regions based on rule
# Color-code ATL vs BTL points
Exercise: Characterizing Points That Flip Labels π
The Problem
Question: When you increase threshold a (for feature x), which points flip from "Positive" to "Negative"?
Setup:
Original rule: IF (x β₯ a) AND (y β₯ b) THEN Positive
New rule: IF (x β₯ a') AND (y β₯ b) THEN Positive
Where: a' > a (threshold increased)
Solution
Points that flip label:
- Must satisfy:
a β€ x < a'(between old and new threshold) - Must satisfy:
y β₯ b(still above y threshold) - Region: A horizontal strip between the two vertical lines
Visual Example:
Mathematical Characterization
Points that flip from Positive β Negative:
Region: { (x, y) | a β€ x < a' AND y β₯ b }
Points that flip from Negative β Positive:
None! (Increasing threshold only removes points, never adds)
Key Insight:
- Only points in the "removed strip" flip labels
- The strip is bounded by:
- Left:
x = a(old threshold) - Right:
x = a'(new threshold) - Bottom:
y = b(y threshold) - Top: Infinity
- Left:
General Case: Changing Multiple Thresholds
Question: What happens when you change both thresholds?
Case 1: Increase both thresholds
Old: x β₯ a AND y β₯ b
New: x β₯ a' AND y β₯ b' (where a' > a, b' > b)
Points that flip: Region shrinks
- Removed: { (x, y) | (a β€ x < a' AND y β₯ b) OR (x β₯ a' AND b β€ y < b') }
Case 2: Increase one, decrease the other
Old: x β₯ a AND y β₯ b
New: x β₯ a' AND y β₯ b' (where a' > a, b' < b)
Points that flip:
- Lost: { (x, y) | a β€ x < a' AND y β₯ b }
- Gained: { (x, y) | x β₯ a' AND b' β€ y < b }
Visual Example:
Visualizing Decision Surfaces: Practical Examples π
Example 1: Fraud Detection
Features:
- X: Transaction amount ($)
- Y: Account age (days)
Rule: IF (amount β₯ $1000) AND (age < 30 days) THEN Fraud
Decision Surface:
- High-risk region: Bottom-right quadrant
- Low-risk region: All other quadrants
Visual Example:
Example 2: Credit Approval
Features:
- X: Credit score
- Y: Income ($)
Rule: IF (score β₯ 700) OR (income β₯ $50,000) THEN Approve
Decision Surface:
- Approval region: L-shaped (three quadrants)
- Rejection region: Bottom-left quadrant only
Visual Example:
Example 3: Quality Control
Features:
- X: Defect count
- Y: Production time (hours)
Rule: IF (defects β₯ 5) AND (time β₯ 8 hours) THEN Reject
Decision Surface:
- Reject region: Top-right quadrant
- Accept region: All other quadrants
Visual Example:
Different rule expressions create different decision surfaces. Understanding these geometric partitions helps you choose the right rules for your use case.
Best Practices for Rule-Based Decision Surfaces β
1. Visualize Before Deploying
Always visualize your decision surfaces to:
- Understand what regions are being classified
- Identify potential edge cases
- Verify rule logic matches business requirements
2. Consider Feature Scaling
Problem: If features have very different scales, decision surfaces may be skewed.
Solution: Normalize or standardize features before applying thresholds.
3. Use Orthogonal Cuts When Possible
Orthogonal cut lines (perpendicular to axes) are:
- Easier to interpret
- Simpler to visualize
- More intuitive for stakeholders
4. Document Threshold Rationale
For each threshold, document:
- Why this value was chosen
- What region it creates
- How it affects classification
5. Monitor Decision Surface Coverage
Track:
- How many points fall in each region
- Distribution of points across quadrants
- Changes over time (drift detection)
Summary Table π
| Concept | Definition | Visual Result |
|---|---|---|
| Half-Space | Region on one side of a line | Infinite region (half-plane) |
| AND Rule | x β₯ a AND y β₯ b | Rectangular quadrant |
| OR Rule | x β₯ a OR y β₯ b | L-shaped region |
| Orthogonal Cuts | Perpendicular threshold lines | Four quadrants |
| Decision Surface | Boundary between classes | Geometric partition |
Final Thoughts π
Decision surfaces transform abstract rule expressions into concrete geometric partitions. Understanding how thresholds create these surfaces is crucial for:
- Interpreting rule-based systems
- Optimizing threshold selection
- Explaining model behavior to stakeholders
- Debugging classification errors
Key Takeaways:
β Half-spaces are the building blocks of decision surfaces β AND rules create rectangular regions (intersections) β OR rules create L-shaped regions (unions) β Orthogonal cuts divide space into quadrants β Threshold changes shift decision boundaries β Lattice ordering helps understand rule relationships
Visualize your rules to understand your model! π¨
Tomorrow's Preview: Day 21 - Coming soon! ππ―




