@@ -134,6 +134,19 @@ def check_neighbors_object(nn_name, nn_object, additional_neighbor=0):
134
134
135
135
136
136
def get_classes_counts (y ):
137
+ """Compute the counts of each class present in `y`.
138
+
139
+ Parameters
140
+ ----------
141
+ y : ndarray of shape (n_samples,)
142
+ The target array.
143
+
144
+ Returns
145
+ -------
146
+ classes_counts : dict
147
+ A dictionary where the keys are the class labels and the values are the
148
+ counts for each class.
149
+ """
137
150
unique , counts = np .unique (y , return_counts = True )
138
151
if is_dask_collection (unique ):
139
152
from dask import compute
@@ -542,8 +555,14 @@ def check_sampling_strategy(
542
555
correspond to the targeted classes. The values correspond to the
543
556
desired number of samples for each class.
544
557
545
- y : ndarray of shape (n_samples,)
546
- The target array.
558
+ classes_counts : dict or ndarray of shape (n_samples,)
559
+ A dictionary where the keys are the class present in `y` and the values
560
+ are the counts. The function :func:`~imblearn.utils.get_classes_count`
561
+ provides such a dictionary, giving `y` as an input.
562
+
563
+ .. deprecated:: 0.7
564
+ Passing the array `y` is deprecated from 0.7 and will be removed
565
+ in 0.9.
547
566
548
567
sampling_type : {{'over-sampling', 'under-sampling', 'clean-sampling'}}
549
568
The type of sampling. Can be either ``'over-sampling'``,
@@ -567,6 +586,15 @@ def check_sampling_strategy(
567
586
" instead." .format (SAMPLING_KIND , sampling_type )
568
587
)
569
588
589
+ if hasattr (y , "__array__" ):
590
+ warnings .warn (
591
+ f"Passing that array of target `y` is deprecated in 0.7 and will "
592
+ f"raise an error from 0.9. Instead, pass `y` to "
593
+ "imblearn.utils.get_classes_counts function to get the "
594
+ "dictionary." , FutureWarning
595
+ )
596
+ classes_counts = get_classes_counts (classes_counts )
597
+
570
598
if len (classes_counts ) <= 1 :
571
599
raise ValueError (
572
600
"The target 'y' needs to have more than 1 class."
0 commit comments