6.5 Rule List Tree

Rule List Tree right

R figure

Code
x <- c(0,400,400,500,500)
y <- c(0,  0,300,300,500)

h <- 500 
w <- 500 

grid.step <- 100


plot( c(0,w), c(0,h),  
     xaxs = "i",yaxs = "i",
     xaxt = 'n', yaxt = 'n',
     type = "n",
     xlab = "Negatives", ylab = "Positives")
     

gx <- grid.step
while (gx <= w) {
  abline(v = gx, col="gray", lty="dotted")
  gx <- gx + grid.step
}
gy <- grid.step
while (gy <= h) {
  abline(h = gy, col="gray", lty="dotted")
  gy <- gy + grid.step
}

plotsplit <- function(l,r,m,labels,oo,pp,qq) {
    segments(x[l],y[l],x[r],y[r],lty=3,col="black")
    text( (x[l]+x[r])/2+oo[1], (y[l]+y[r])/2+oo[2], labels[1])
    text( (x[l]+x[m])/2+pp[1], (y[l]+y[m])/2+pp[2], labels[2])
    text( (x[m]+x[r])/2+qq[1], (y[m]+y[r])/2+qq[2], labels[3])
    arrows( (x[l]+x[r])/2, (y[l]+y[r])/2, x[m]+oo[1], y[m]+pp[2], code=2, length=0.1 )
}

plotsplit(1,5,2,c("A","B","C"),c(-10,10),c(0,10),c(10,-10))
plotsplit(2,5,3,c("","D","E"),c(10,-10),c(-10,-10),c(-10,10))
plotsplit(3,5,4,c("","F","G"),c(-10,-10),c(0,10),c(-10,-40))

lines( x[1:2], y[1:2], lwd=5, col='red')
lines( x[2:3], y[2:3], lwd=3, col='green')
lines( x[3:4], y[3:4], lwd=3, col='red')
lines( x[4:5], y[4:5], lwd=5, col='green')
points(x,y,pch=19,col='black')

lines( c(0,  0,  0,100,500), c(0,300,500,500,500), lwd=5, type='o',col='blue')

text(  15, 150, col="blue", "D")
text(  15, 400, col="blue", "G")
text(  50, 485, col="blue", "F")
text( 300, 485, col="blue", "B")

Python Figure

Code
import matplotlib.pyplot as plt

x = [0, 400, 400, 500, 500]
y = [0,   0, 300, 300, 500]

h = 500
w = 500
grid_step = 100

plt.figure(figsize=(6, 6))
plt.xlim(0, w)
(0.0, 500.0)
Code
plt.ylim(0, h)
(0.0, 500.0)
Code
plt.xlabel("Negatives")
plt.ylabel("Positives")
plt.xticks([])
([], [])
Code
plt.yticks([])
([], [])
Code
plt.gca().set_aspect('equal')

for gx in range(grid_step, w + 1, grid_step):
    plt.axvline(x=gx, color="gray", linestyle="dotted")
for gy in range(grid_step, h + 1, grid_step):
    plt.axhline(y=gy, color="gray", linestyle="dotted")

def plotsplit(l, r, m, labels, oo, pp, qq):
    plt.plot([x[l - 1], x[r - 1]], [y[l - 1], y[r - 1]], linestyle="dashed", color="black")
    plt.text((x[l - 1] + x[r - 1]) / 2 + oo[0], (y[l - 1] + y[r - 1]) / 2 + oo[1], labels[0])
    plt.text((x[l - 1] + x[m - 1]) / 2 + pp[0], (y[l - 1] + y[m - 1]) / 2 + pp[1], labels[1])
    plt.text((x[m - 1] + x[r - 1]) / 2 + qq[0], (y[m - 1] + y[r - 1]) / 2 + qq[1], labels[2])
    plt.arrow((x[l - 1] + x[r - 1]) / 2, (y[l - 1] + y[r - 1]) / 2,
              x[m - 1] - (x[l - 1] + x[r - 1]) / 2 + oo[0],
              y[m - 1] - (y[l - 1] + y[r - 1]) / 2 + pp[1],
              head_width=10, head_length=15, fc='black', ec='black', length_includes_head=True)

plotsplit(1, 5, 2, ["A", "B", "C"], [-10, 10], [0, 10], [10, -10])
plotsplit(2, 5, 3, ["", "D", "E"], [10, -10], [-10, -10], [-10, 10])
plotsplit(3, 5, 4, ["", "F", "G"], [-10, -10], [0, 10], [-10, -40])

plt.plot(x[0:2], y[0:2], linewidth=5, color='red')
plt.plot(x[1:3], y[1:3], linewidth=3, color='green')
plt.plot(x[2:4], y[2:4], linewidth=3, color='red')
plt.plot(x[3:5], y[3:5], linewidth=5, color='green')
plt.scatter(x, y, color='black', zorder=5)

plt.plot([0, 0, 0, 100, 500], [0, 300, 500, 500, 500], linewidth=5, color='blue')

plt.text(15, 150, "D", color="blue")
plt.text(15, 400, "G", color="blue")
plt.text(50, 485, "F", color="blue")
plt.text(300, 485, "B", color="blue")

plt.show()

Rule List Tree left

Code
graph TD;
    L1["B: [0+, 4-]"]:::red
    L2["D: [3+, 0-]"]:::green
    L3["F: [0+, 1-]"]:::red
    N1["A: Gills"]
    N2["C: Teeth"]
    N3["E: Length"]
    L4["G: [2+, 0-]"]:::green

    N1 -- "≠yes" --> N2
    N1 --> L1
    N2 -- "≠many" --> N3
    N2 --> L2
    N3 -- "≠4" --> L4
    N3 --> L3

    classDef red fill:#f04030,stroke:#000,stroke-width:1px;
    classDef green fill:#00a000,stroke:#000,stroke-width:1px;
graph TD;
    L1["B: [0+, 4-]"]:::red
    L2["D: [3+, 0-]"]:::green
    L3["F: [0+, 1-]"]:::red
    N1["A: Gills"]
    N2["C: Teeth"]
    N3["E: Length"]
    L4["G: [2+, 0-]"]:::green

    N1 -- "≠yes" --> N2
    N1 --> L1
    N2 -- "≠many" --> N3
    N2 --> L2
    N3 -- "≠4" --> L4
    N3 --> L3

    classDef red fill:#f04030,stroke:#000,stroke-width:1px;
    classDef green fill:#00a000,stroke:#000,stroke-width:1px;