Base.transformFeatureToIntegers

Base.transformFeatureToIntegers(featureToConvert, *, useLog=None)

Represent each unique value in a feature with a unique integer.

Modify this object so that the chosen feature is removed and a new integer valued feature is added with values 0 to n-1, one for each of n unique values present in the original feature.

Parameters:
  • featureToConvert (int or str) – The index or name of the feature being replaced.

  • useLog (bool, None) – Local control for whether to send object creation to the logger. If None (default), use the value as specified in the “logger” “enabledByDefault” configuration option. If True, send to the logger regardless of the global option. If False, do NOT send to the logger, regardless of the global option.

Examples

>>> lst = [[1, 'a', 1], [2, 'b', 2], [3, 'c', 3]]
>>> featureNames = ['keep1', 'transform', 'keep2']
>>> X = nimble.data(lst, featureNames=featureNames)
>>> mapping = X.transformFeatureToIntegers('transform')
>>> mapping
{0: 'a', 1: 'b', 2: 'c'}
>>> X
<DataFrame 3pt x 3ft
     keep1  transform  keep2
   ┌────────────────────────
 0 │   1        0        1
 1 │   2        1        2
 2 │   3        2        3
>

Keywords: map, categories, nominal, categorical, ordinal, unencode