import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.widgets import Cursor
# Use %matplotlib widget for interactive plots
%matplotlib widget2024/25 Semester B¶
Extracted from the discussion page on Interactive Decision Tree Construction.
# Load the CSV file
df = pd.read_csv('segment.csv', skipinitialspace=True)
# Filter out entries with missing fields
df = df.dropna()
# Create the scatter plot
fig, ax = plt.subplots()
# Plot accuracy against depth
scatter = ax.scatter(df['depth'], df['accuracy'])
# Adding cursor widget for interactivity
cursor = Cursor(ax, useblit=True, color='red', linewidth=1)
# Adding labels and title
ax.set_xlabel('Depth')
ax.set_ylabel('Accuracy')
ax.set_title('Scatter Plot of Accuracy vs Depth')
# Add hover functionality to show names
# Create a dictionary to map each point to its name
names = df['name'].tolist()
depths = df['depth'].tolist()
accuracies = df['accuracy'].tolist()
# Function to update annotation
annot = ax.annotate("", xy=(0,0), xytext=(20,-20),
                    textcoords="offset points",
                    bbox=dict(boxstyle="round", fc="w"),
                    arrowprops=dict(arrowstyle="->"))
annot.set_visible(False)
def update_annot(ind):
    pos = scatter.get_offsets()[ind["ind"][0]]
    annot.xy = pos
    text = "{}".format(" ".join([names[n] for n in ind["ind"]]))
    annot.set_text(text)
    annot.get_bbox_patch().set_alpha(0.8)
def hover(event):
    vis = annot.get_visible()
    if event.inaxes == ax:
        cont, ind = scatter.contains(event)
        if cont:
            update_annot(ind)
            annot.set_visible(True)
            fig.canvas.draw_idle()
        else:
            if vis:
                annot.set_visible(False)
                fig.canvas.draw_idle()
# Connect the hover function to the figure
fig.canvas.mpl_connect("motion_notify_event", hover)
# Show the plot
plt.show()Course Records¶
- name: Tsz Wan CHOI
- semester: 2020/21 Semester B
- accuracy: 96.2963%
- deph: 8
Split on hue-mean AND region-centroid-row (In Set): N1 grass(207.0)
Split on hue-mean AND region-centroid-row (Not in Set)
|   Split on value-mean AND region-centroid-row (In Set): N3 sky(220.0)
|   Split on value-mean AND region-centroid-row (Not in Set)
|   |   Split on region-centroid-row AND saturation-mean (In Set)
|   |   |   Split on rawred-mean AND rawgreen-mean (In Set)
|   |   |   |   Split on rawred-mean AND rawgreen-mean (In Set): N9 foliage(156.0/1.0)
|   |   |   |   Split on rawred-mean AND rawgreen-mean (Not in Set)
|   |   |   |   |   Split on region-centroid-row AND rawgreen-mean (In Set)
|   |   |   |   |   |   Split on hue-mean AND rawred-mean (In Set): N13 foliage(13.0)
|   |   |   |   |   |   Split on hue-mean AND rawred-mean (Not in Set)
|   |   |   |   |   |   |   Split on exgreen-mean AND region-centroid-col (In Set): N15 window(224.0/24.0)
|   |   |   |   |   |   |   Split on exgreen-mean AND region-centroid-col (Not in Set): N16 foliage(33.0/3.0)
|   |   |   |   |   Split on region-centroid-row AND rawgreen-mean (Not in Set): N12 cement(208.0)
|   |   |   Split on rawred-mean AND rawgreen-mean (Not in Set): N8 brickface(203.0)
|   |   Split on region-centroid-row AND saturation-mean (Not in Set): N6 path(236.0)- name: Zeyu LIU
- semester: 2023/24 Semester B
- accuracy: 95.6790%
- deph: 3
=== Classifier model (full training set) ===
Split on region-centroid-row AND rawgreen-mean (In Set)
|   Split on exblue-mean AND value-mean (In Set)
|   |   Split on exblue-mean AND value-mean (In Set): N5 sky(220.0)
|   |   Split on exblue-mean AND value-mean (Not in Set): N6 grass(207.0)
|   Split on exblue-mean AND value-mean (Not in Set)
|   |   Split on region-centroid-row AND value-mean (In Set): N7 path(236.0)
|   |   Split on region-centroid-row AND value-mean (Not in Set): N8 cement(222.0/22.0)
Split on region-centroid-row AND rawgreen-mean (Not in Set)
|   Split on hue-mean AND intensity-mean (In Set)
|   |   Split on hue-mean AND intensity-mean (In Set): N13 window(33.0/4.0)
|   |   Split on hue-mean AND intensity-mean (Not in Set): N14 brickface(210.0/7.0)
|   Split on hue-mean AND intensity-mean (Not in Set)
|   |   Split on hue-mean AND saturation-mean (In Set): N11 foliage(173.0/12.0)
|   |   Split on hue-mean AND saturation-mean (Not in Set): N12 window(199.0/40.0)
Time taken to build model: 283.63 seconds
=== Confusion Matrix ===
   a   b   c   d   e   f   g   <-- classified as
 123   0   0   0   2   0   0 |   a = brickface
   0 110   0   0   0   0   0 |   b = sky
   3   0 110   1   8   0   0 |   c = foliage
   1   0   0 102   6   0   1 |   d = cement
   2   0   6   3 115   0   0 |   e = window
   0   0   0   0   0  94   0 |   f = path
   0   0   0   1   0   1 121 |   g = grass
=== Summary ===
Correctly Classified Instances 775 95.6790 %
Incorrectly Classified Instances 35 4.3210 %