nimble.fillMatching

nimble.fillMatching(learnerName, matchingElements, trainX, arguments=None, points=None, features=None, *, useLog=None, **kwarguments)

Fill matching values using imputation learners.

Transform the data in the trainX object to replace all matching values with values calculated by the learner.

Parameters:
  • learnerName (str) – The learner to be called. This can be a string in the form ‘package.learner’ or the learner class object.

  • trainX (nimble Base object) – Data to be used for training.

  • arguments (dict) – Mapping argument names (strings) to their values, to be used during training and application (e.g., {‘dimensions’:5, ‘k’:5}). To provide an argument that is an object from the same package as the learner, use a nimble.Init object with the object name and its instantiation arguments (e.g., {‘optimizer’: nimble.Init(‘SGD’, learning_rate=0.01}). Note: learner arguments can also be passed as kwarguments so this dictionary will be merged with any keyword arguments.

  • points (identifier, list of identifiers, None) – May be a single point name or index, an iterable, container of point names and/or indices. None indicates application to all points, otherwise only the matching values in the specified points will be modified.

  • features (identifier, list of identifiers, None) – May be a single feature name or index, an iterable, container of feature names and/or indices. None indicates application to all features, otherwise only the matching values in the specified features will be modified.

  • 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.

  • kwarguments – Keyword arguments specified variables that are passed to the learner. These are combined with the arguments parameter. To provide an argument that is an object from the same package as the learner, use a nimble.Init object with the object name and its instantiation arguments (e.g., optimizer=nimble.Init(‘SGD’, learning_rate=0.01)).

Examples

Fill missing values based on k-nearest neighbors classifier.

>>> lst = [[1, None, None],
...        [1, 3, 6],
...        [2, 1, 6],
...        [1, 3, 7],
...        [None, 3, None]]
>>> X = nimble.data(lst)
>>> toMatch = nimble.match.missing
>>> nimble.fillMatching('nimble.KNNImputation', toMatch, X,
...                     mode='classification', k=3)
>>> X
<Matrix 5pt x 3ft
       0      1      2
   ┌────────────────────
 0 │ 1.000  3.000  6.000
 1 │ 1.000  3.000  6.000
 2 │ 2.000  1.000  6.000
 3 │ 1.000  3.000  7.000
 4 │ 1.000  3.000  6.000
>

Fill last feature zeros based on k-nearest neighbors regressor.

>>> lst = [[1, 0, 0],
...        [1, 3, 6],
...        [2, 1, 6],
...        [1, 3, 7],
...        [0, 3, 0]]
>>> X = nimble.data(lst)
>>> toMatch = nimble.match.zero
>>> nimble.fillMatching('nimble.KNNImputation', toMatch, X,
...                     features=-1, k=3, mode='regression')
>>> X
<Matrix 5pt x 3ft
       0      1      2
   ┌────────────────────
 0 │ 1.000  0.000  6.333
 1 │ 1.000  3.000  6.000
 2 │ 2.000  1.000  6.000
 3 │ 1.000  3.000  7.000
 4 │ 0.000  3.000  6.333
>

Keywords: inputation, replace, missing, empty, NaN, nan, clean