Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MC-CCR implementation #102

Merged
merged 22 commits into from
Jun 21, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add typing
  • Loading branch information
dddddddddtd committed May 8, 2023
commit 138276c36ff57fe2ffbeb4cfe07ae1aa30624f22
5 changes: 3 additions & 2 deletions multi_imbalance/resampling/ccr.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import typing
from collections import Counter
from typing import Tuple

Expand Down Expand Up @@ -138,7 +139,7 @@ def _clean_and_generate(self, minority_examples: np.ndarray, majority_examples:

return clean_majority_examples, generated

def distances(self, minority_example, majority_examples):
def distances(self, minority_example: np.ndarray, majority_examples: np.ndarray) -> np.ndarray:
return (abs(minority_example - majority_examples)).sum(1)


Expand Down Expand Up @@ -213,7 +214,7 @@ def _fit_resample(self, X: np.ndarray, y: np.ndarray) -> Tuple[np.ndarray, np.nd
final_y = np.hstack([np.full((class_X[clazz].shape[0],), clazz) for clazz, _ in sorted_class_counts])
return final_X, final_y

def _number_of_classes_with_higher_count(self, sorted_class_counts, i):
def _number_of_classes_with_higher_count(self, sorted_class_counts: dict[typing.Any, int], i: int) -> int:
number_of_classes_with_higher_count = 0
_, current_class_count = sorted_class_counts[i]
for _, class_count in sorted_class_counts[:i]:
Expand Down