bin_ratings#
- bin_ratings(ratings=None, nbins=4, verbose=True, ignore_invalid=False)[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:
- ratings
list|np.ndarray Ratings on a continuous scale.
- nbins
int The number of discrete ratings to resample. Default set to
4.- verbosebool
If
True, warnings will be returned.- ignore_invalidbool
If
False(default), an error 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. IfTrue, the discretisation will process anyway. This option can be useful for plotting.
- ratings
- Returns:
- discreteRatings
np.ndarray New rating array only containing integers between 1 and
nbins.- out
dict Dictionary containing logs of the discretisation process:
'confbins': list or 1d array-like - If the ratings werereampled, 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 tolarger 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.
- discreteRatings
- Raises:
- ValueError:
If the confidence ratings contains a lot of identical values and
ignore_invalidisFalse.
Examples
>>> import numpy as np >>> from cpm.utils.metad import bin_ratings >>> 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]) >>> bin_ratings(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})