TrainedLearner.retrain¶
- TrainedLearner.retrain(trainX, trainY=None, arguments=None, randomSeed=None, *, useLog=None, **kwarguments)¶
Train the model on new data.
Adjust the learner model by providing new training data and/or changing the learner’s argument values. Previously set argument values for this learner model will remain the same, unless overridden by new arguments or kwarguments. If new data is provided, the learner will be trained on that data only, discarding the previous data.
- Parameters:
trainX (nimble Base object) – Data to be used for training.
trainY (identifier, nimble Base object) –
identifier - The name or index of the feature in
trainX
containing the labels.nimble Base object - contains the labels that correspond to
trainX
.
arguments (dict) – Mapping argument names (strings) to their values, to be used during training. These must be singular values, retrain does not implement cross-validation for multiple argument sets. Will be merged with kwarguments.
randomSeed (int) – Set a random seed for the operation. When not None, allows for reproducible results for each function call. Ignored if learner does not depend on randomness.
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. Must be singular values, retrain does not implement cross-validation for multiple arguments sets. Will be merged with
arguments
.
See also
Examples
Changing the training data.
>>> lstTrainX1 = [[1, 1], [2, 2], [3, 3]] >>> trainX1 = nimble.data(lstTrainX1) >>> lstTrainY1 = [[1], [2], [3]] >>> trainY1 = nimble.data(lstTrainY1) >>> lstTestX = [[8, 8], [-3, -3]] >>> testX = nimble.data(lstTestX) >>> tl = nimble.train('nimble.KNNClassifier', trainX1, trainY1) >>> tl.apply(testX) <Matrix 2pt x 1ft 0 ┌── 0 │ 3 1 │ 1 > >>> lstTrainX2 = [[4, 4], [5, 5], [6, 6]] >>> trainX2 = nimble.data(lstTrainX2) >>> lstTrainY2 = [[4], [5], [6]] >>> trainY2 = nimble.data(lstTrainY2) >>> tl.retrain(trainX2, trainY2) >>> tl.apply(testX) <Matrix 2pt x 1ft 0 ┌── 0 │ 6 1 │ 4 >
Changing the learner arguments.
>>> lstTrainX = [[1, 1], [3, 3], [3, 3]] >>> trainX = nimble.data(lstTrainX) >>> lstTrainY = [[1], [3], [3]] >>> trainY = nimble.data(lstTrainY) >>> lstTestX = [[1, 1], [3, 3]] >>> testX = nimble.data(lstTestX) >>> tl = nimble.train('nimble.KNNClassifier', trainX, trainY, ... k=1) >>> tl.apply(testX) <Matrix 2pt x 1ft 0 ┌── 0 │ 1 1 │ 3 > >>> tl.retrain(trainX, trainY, k=3) >>> tl.apply(testX) <Matrix 2pt x 1ft 0 ┌── 0 │ 3 1 │ 3 >