TrainedLearner.apply

TrainedLearner.apply(testX, arguments=None, scoreMode=None, *, useLog=None, **kwarguments)

Apply the learner to the test data.

Return the application of this learner to the given test data. The output depends on the type of learner:

  • classification: The predicted labels

  • regression: The predicted values

  • cluster : The assigned cluster number

  • transformation: The transformed data

If testX has pointNames and the output object has the same number of points, the pointNames from testX will be applied to the output object. Equivalent to having called trainAndApply, as long as the data and parameter setup for training was the same.

Parameters:
  • testX (nimble Base object) – Data set on which the trained learner will be applied (i.e. performing prediction, transformation, etc. as appropriate to the learner).

  • arguments (dict) – Mapping argument names (strings) to their values, to be used during training and application. eg. {‘dimensions’:5, ‘k’:5} To make use of multiple permutations, specify different values for a parameter as a tuple. eg. {‘k’: (1,3,5)} will generate an error score for the learner when the learner was passed all three values of k, separately. These will be merged with kwarguments for the learner.

  • scoreMode (str, None) – For learners that offer a scoring method, this can be set to ‘bestScore’ or ‘allScores’. The ‘bestScore’ option returns two features, the predicted class and score for that class. The ‘allScores’ option will construct a matrix where each feature represents the scores for that class.

  • useLog (bool, None) – Local control for whether to send results/timing 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. To make use of multiple permutations, specify different values for parameters as a tuple. eg. arg1=(1,2,3), arg2=(4,5,6) which correspond to permutations/argument states with one element from arg1 and one element from arg2, such that an example generated permutation/argument state would be arg1=2, arg2=4. Will be merged with arguments.

Returns:

results – The resulting output of applying learner.

Examples

>>> lstTrain = [[1, 0, 0, 1],
...             [0, 1, 0, 2],
...             [0, 0, 1, 3],
...             [1, 0, 0, 1],
...             [0, 1, 0, 2],
...             [0, 0, 1, 3]]
>>> lstTestX = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
>>> trainData = nimble.data(lstTrain)
>>> testX = nimble.data(lstTestX)
>>> tl = nimble.train('nimble.KNNClassifier', trainX=trainData,
...                   trainY=3)
>>> tl.apply(testX)
<Matrix 3pt x 1ft
     0
   ┌──
 0 │ 1
 1 │ 2
 2 │ 3
>