mlens.base.id_train module

ML-ENSEMBLE

author:Sebastian Flennerhag
copyright:2017
licence:MIT

Class for identifying a training set after an estimator has been fitted. Used for determining whether a predict or transform method should use cross validation to create predictions, or estimators fitted on full training data.

class mlens.base.id_train.IdTrain(size=10)[source]

Bases: mlens.externals.sklearn.base.BaseEstimator

Container to identify training set.

Samples a random subset from set passed to the fit method, to allow identification of the training set in a transform or predict method.

Parameters:size (int) – size to sample. A random subset of size [size, size] will be stored in the instance.
fit(X)[source]

Sample a training set.

Parameters:X (array-like) – training set to sample observations from.
Returns:self – fitted instance with stored sample.
Return type:obj
is_train(X)[source]

Check if an array is the training set.

Parameters:X (array-like) – training set to sample observations from.
Returns:self – fitted instance with stored sample.
Return type:obj
mlens.base.id_train.permutation(x)

Randomly permute a sequence, or return a permuted range.

If x is a multi-dimensional array, it is only shuffled along its first index.

Parameters:x (int or array_like) – If x is an integer, randomly permute np.arange(x). If x is an array, make a copy and shuffle the elements randomly.
Returns:out – Permuted sequence or array range.
Return type:ndarray

Examples

>>> np.random.permutation(10)
array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6])
>>> np.random.permutation([1, 4, 9, 12, 15])
array([15,  1,  9,  4, 12])
>>> arr = np.arange(9).reshape((3, 3))
>>> np.random.permutation(arr)
array([[6, 7, 8],
       [0, 1, 2],
       [3, 4, 5]])