Skip to content

Commit

Permalink
Fix multitarget stratification (#1308)
Browse files Browse the repository at this point in the history
* data: add data for multitarget classification

* fix: prevent stratify with unbalanced classes

* test: add multitarget classification stratify test

* Automated autopep8 fixes

* fix: fix path for test data

* Automated autopep8 fixes

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
DRMPN and github-actions[bot] committed Jul 2, 2024
1 parent 0f22840 commit 03e4736
Show file tree
Hide file tree
Showing 3 changed files with 19,242 additions and 1 deletion.
10 changes: 10 additions & 0 deletions fedot/core/data/data_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ def _are_stratification_allowed(data: Union[InputData, MultiModalData], split_ra
if test_size < labels_count:
return False

# check that multitarget classes can be stratified
if data.target.ndim == 2:
y = np.array([" ".join(row.astype("str")) for row in data.target])

classes, y_indices = np.unique(y, return_inverse=True)

class_counts = np.bincount(y_indices)
if np.min(class_counts) < 2:
return False

return True


Expand Down
Loading

0 comments on commit 03e4736

Please sign in to comment.