Sughosh Dixit
Sughosh P Dixit
2025-11-20 β€’ 10 min read

Day 20: Two-Feature Decision Surfaces from Rule Expressions

Article Header Image

TL;DR

Quick summary

Visualize how rule expressions create decision surfaces in two-dimensional feature space. Learn to understand half-space intersections, orthogonal partitions, and how threshold changes affect classification regions.

Key takeaways
  • Day 20: Two-Feature Decision Surfaces from Rule Expressions
Preview

Day 20: Two-Feature Decision Surfaces from Rule Expressions

Visualize how rule expressions create decision surfaces in two-dimensional feature space. Learn to understand half-space intersections, orthogonal partitions, and how threshold changes affect classification regions.

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:

Decision Surface Visualization

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 β‰₯ a creates a vertical half-space (everything to the right of x = a)
  • y β‰₯ b creates a horizontal half-space (everything above y = b)

Visual Example:

Half-Spaces Visualization

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:

Half-Space Combinations

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:

  1. Q1 (Top-Right): x β‰₯ 1000 AND y β‰₯ 30 β†’ High Risk βœ…
  2. Q2 (Top-Left): x < 1000 AND y β‰₯ 30 β†’ Low Risk
  3. Q3 (Bottom-Left): x < 1000 AND y < 30 β†’ Low Risk
  4. Q4 (Bottom-Right): x β‰₯ 1000 AND y < 30 β†’ Low Risk

Visual Example:

Quadrant Partition

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:

AND Rule Decision Surface

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:

OR Rule Decision Surface

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:

Complex Rule Decision Surface

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:

Lattice Ordering

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:

  1. Plotting data points in 2D feature space
  2. Drawing threshold lines (cut lines)
  3. Shading regions based on rule satisfaction
  4. Color-coding points as ATL (positive) or BTL (negative)

Visual Example:

ATL/BTL Scatter Plot

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:

Label Flip Region

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

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:

Multiple Threshold Changes

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:

Fraud Detection Decision Surface

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:

Credit Approval Decision Surface

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:

Quality Control Decision Surface

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! πŸ“ŠπŸŽ―


Sughosh P Dixit
Sughosh P Dixit
Data Scientist & Tech Writer
10 min read
Previous Post

Day 2 β€” Expressions as Algebra: Tokens, Precedence, and Infix β†’ Postfix

How to teach computers to read and evaluate expressions step by step β€” by tokenizing text, enforcing operator precedence, and converting rules to postfix (RPN) form for speed, clarity and consistency.

Next Post

Day 21: Contingency Tables and Bin-Wise Uplift

Learn to quantify uplift and effectiveness across bins and segments using contingency tables. Understand cell counts, rates, marginalization, and how to avoid Simpson's paradox when analyzing bin-wise trends.