gen_poly_features#

fastcan.narx.gen_poly_features(X, ids, skip_indices=None, batch_size=16)#

Generator to make polynomial features.

Added in version 0.6.0.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – The data to transform, column by column.

  • ids (array-like of shape (n_outputs, degree)) – The unique id numbers of output features, which are formed of non-negative int values.

  • skip_indices (array-like, default=None) – Indices of features that have already been selected and can be skipped.

  • batch_size (int, default=16) –

    Number of polynomial features to generate in each batch.

    Added in version 0.6.1.

Yields:
  • index (ndarray of shape (batch_size,)) – The indices of the yielded features.

  • feature (ndarray of shape (n_samples, batch_size)) – A batch of polynomial features.

Examples

>>> import numpy as np
>>> from fastcan.narx import gen_poly_features, make_poly_ids
>>> ids = make_poly_ids(2, 2)
>>> X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
>>> for i, feat in gen_poly_features(X, ids, batch_size=2):
...     print(i, feat)
[0 1] [[1. 2.]
 [3. 4.]
 [5. 6.]
 [7. 8.]]
[2 3] [[ 1.  2.]
 [ 9. 12.]
 [25. 30.]
 [49. 56.]]
[4] [[ 4.]
 [16.]
 [36.]
 [64.]]