Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -696,13 +696,16 @@ def _calc_binary_ig(orderline, c1, c2):
c2_count = 0

# evaluate each split point
for split in range(len(orderline)):
for split in range(len(orderline) - 1):
next_class = orderline[split][1] # +1 if this class, -1 if other
if next_class > 0:
c1_count += 1
else:
c2_count += 1

if orderline[split][0] == orderline[split + 1][0]:
continue

left_prop = (split + 1) / total_all
ent_left = _binary_entropy(c1_count, c2_count)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Tests for shapelet transform functions."""

__maintainer__ = []

from aeon.transformations.collection.shapelet_based._shapelet_transform import (
_calc_binary_ig,
)


def test_calc_binary_ig_identical_splits():
"""Test binary IG calculation correctly handles identical split values.

Regression test for Issue #1322. Ensures that split points are not
evaluated between identical distance values, which previously resulted
in incorrect Information Gain calculation.
"""
orderline = [(2, -1), (2, -1), (2, 1), (3, 1), (3, 1)]

# Class 1 has 3 items, Class -1 has 2 items
c1, c2 = 3, 2

ig = _calc_binary_ig(orderline, c1, c2)

# The expected IG is approx 0.42.
assert 0.41 < ig < 0.43