metadpy.utils.discreteRatings#
- metadpy.utils.discreteRatings(ratings: Union[list, ndarray], nbins: int = 4, verbose: bool = True, ignore_invalid: bool = False) Tuple[ndarray, Dict[str, list]] [source]#
Convert from continuous to discrete ratings.
Resample if quantiles are equal at high or low end to ensure proper assignment of binned confidence
- Parameters
- ratingslist | np.ndarray
Ratings on a continuous scale.
- nbinsint
The number of discrete ratings to resample. Defaut set to 4.
- verboseboolean
If True, warning warnings be returned.
- ignore_invalidbool
If False (default), an arreor will be raised in case of impossible discretisation of the confidence ratings. This is mostly due to identical values and SDT values should not be extracted from the data. If True the discretisation will process anyway. This option can be usefull for plotting.
- Returns
- discreteRatingsnp.ndarray
New rating array only containing integers between 1 and nbins.
- outdict
- Dictionary containing logs of the discrization process:
- ‘confbins’: list or 1d array-like - If the ratings were
reampled, a list containing the new ratings and the new low or hg threshold, appened before or after the rating, respectively. Else, only returns the ratings.
- ‘rebin’: boolean - If True, the ratings were resampled due to
larger numbers of highs or low ratings.
‘binCount’ : int - Number of bins
Warning
This function will automatically control for bias in high or low confidence ratings. If the first two or the last two quantiles have identical values, low or high confidence trials are excluded (respectively), and the function is run again on the remaining data.
- Raises
- ValueError:
If the confidence ratings contains a lot of identical values and ignore_invalid is False.
Examples
>>> from metadpy.utils import discreteRatings >>> ratings = np.array([ >>> 96, 98, 95, 90, 32, 58, 77, 6, 78, 78, 62, 60, 38, 12, >>> 63, 18, 15, 13, 49, 26, 2, 38, 60, 23, 25, 39, 22, 33, >>> 32, 27, 40, 13, 35, 16, 35, 73, 50, 3, 40, 0, 34, 47, >>> 52, 0, 0, 0, 25, 1, 16, 37, 59, 20, 25, 23, 45, 22, >>> 28, 62, 61, 69, 20, 75, 10, 18, 61, 27, 63, 22, 54, 30, >>> 36, 66, 14, 2, 53, 58, 88, 23, 77, 54]) >>> discreteRatings, out = discreteRatings(ratings) (array([4, 4, 4, 4, 2, 3, 4, 1, 4, 4, 4, 4, 3, 1, 4, 1, 1, 1, 3, 2, 1, 3, 4, 2, 2, 3, 2, 2, 2, 2, 3, 1, 3, 1, 3, 4, 3, 1, 3, 1, 2, 3, 3, 1, 1, 1, 2, 1, 1, 3, 3, 2, 2, 2, 3, 2, 2, 4, 4, 4, 2, 4, 1, 1, 4, 2, 4, 2, 3, 2, 3, 4, 1, 1, 3, 3, 4, 2, 4, 3]), {'confBins': array([ 0., 20., 35., 60., 98.]), 'rebin': 0, 'binCount': 21})