TrainedLearner

class nimble.core.interfaces.TrainedLearner

Returned by nimble.train to access the learner trained model.

Provides methods for interfacing with the trained model including methods for applying, testing and accessing cross-validation results and other learned attributes.

Examples

>>> lst = [[1, 0, 1], [0, 1, 2], [0, 0, 3], [1, 1, 4]] * 10
>>> lstTest = [[1, 0, 1], [0, -1, 2], [0, 1, 2], [1, 1, 4]]
>>> ftNames = ['a', 'b' , 'label']
>>> trainData = nimble.data(lst, featureNames=ftNames)
>>> testData = nimble.data(lstTest, featureNames=ftNames)
>>> tl = nimble.train('nimble.KNNClassifier', trainX=trainData,
...                   trainY='label')
>>> tl.apply(testX=testData[:, :'b'])
<Matrix 4pt x 1ft
     label
   ┌──────
 0 │   1
 1 │   3
 2 │   2
 3 │   4
>
>>> tl.test(testX=testData, testY='label',
...         performanceFunction=nimble.calculate.fractionIncorrect)
0.25

Attributes

arguments

The original arguments passed to the learner.

learnerName

The name of the learner used for training.

learnerType

The type of learner that has been trained.

logID

Identifier for this object within the log.

randomSeed

The random seed used for the learner.

tuning

Tuning object storing validation results.

Methods

apply(testX[, arguments, scoreMode, useLog])

Apply the learner to the test data.

getAttributes()

The attributes associated with this learner.

getScores(testX[, arguments])

The scores for all labels for each data point.

incrementalTrain(trainX[, trainY, ...])

Extend the training of this learner with additional data.

retrain(trainX[, trainY, arguments, ...])

Train the model on new data.

save(outputPath)

Save model to a file.

test(performanceFunction, testX[, testY, ...])

Evaluate the performance of the trained learner.