imblearn.utils.check_ratio

imblearn.utils.check_ratio(ratio, y, sampling_type)[source][source]

Ratio validation for samplers.

Checks ratio for consistent type and return a dictionary containing each targeted class with its corresponding number of pixel.

Parameters:

ratio : str, dict or callable,

Ratio to use for resampling the data set.

  • If str, has to be one of: (i) 'minority': resample the minority class; (ii) 'majority': resample the majority class, (iii) 'not minority': resample all classes apart of the minority class, (iv) 'all': resample all classes, and (v) 'auto': correspond to 'all' with for over-sampling methods and 'not minority' for under-sampling methods. The classes targeted will be over-sampled or under-sampled to achieve an equal number of sample with the majority or minority class.
  • If dict, the keys correspond to the targeted classes. The values correspond to the desired number of samples.
  • If callable, function taking y and returns a dict. The keys correspond to the targeted classes. The values correspond to the desired number of samples.

y : ndarray, shape (n_samples,)

The target array.

sampling_type : str,

The type of sampling. Can be either 'over-sampling' or 'under-sampling'.

Returns:

ratio_converted : dict,

The converted and validated ratio. Returns a dictionary with the key being the class target and the value being the desired number of samples.