econml.iv.sieve.DPolynomialFeatures

class econml.iv.sieve.DPolynomialFeatures(degree=2, interaction_only=False, include_bias=True)[source]

Bases: sklearn.base.TransformerMixin

Featurizer that returns the derivatives of PolynomialFeatures features in a way that’s compatible with the expectations of SieveTSLS’s dt_featurizer parameter.

If the input has shape (n, x) and PolynomialFeatures.transform returns an output of shape (n, f), then transform() will return an array of shape (n, x, f).

Parameters
  • degree (int, default = 2) – The degree of the polynomial features.

  • interaction_only (bool, default = False) – If true, only derivatives of interaction features are produced: features that are products of at most degree distinct input features (so not x[1] ** 2, x[0] * x[2] ** 3, etc.).

  • include_bias (bool, default = True) – If True (default), then include the derivative of a bias column, the feature in which all polynomial powers are zero.

__init__(degree=2, interaction_only=False, include_bias=True)[source]

Methods

__init__([degree, interaction_only, ...])

fit(X[, y])

Compute number of output features.

fit_transform(X[, y])

Fit to data, then transform it.

set_output(*[, transform])

Set output container.

transform(X)

Transform data to derivatives of polynomial features

fit(X, y=None)[source]

Compute number of output features.

Parameters
  • X (array_like, shape (n_samples, n_features)) – The data.

  • y (array, optional) – Not used

Returns

self

Return type

instance

fit_transform(X, y=None, **fit_params)

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters
  • X (array-like of shape (n_samples, n_features)) – Input samples.

  • y (array-like of shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values (None for unsupervised transformations).

  • **fit_params (dict) – Additional fit parameters.

Returns

X_new – Transformed array.

Return type

ndarray array of shape (n_samples, n_features_new)

set_output(*, transform=None)

Set output container.

See Introducing the set_output API for an example on how to use the API.

Parameters

transform ({“default”, “pandas”}, default=None) – Configure output of transform and fit_transform.

  • “default”: Default output format of a transformer

  • “pandas”: DataFrame output

  • None: Transform configuration is unchanged

Returns

self – Estimator instance.

Return type

estimator instance

transform(X)[source]

Transform data to derivatives of polynomial features

Parameters

X (array_like, shape (n_samples, n_features)) – The data to transform, row by row.

Returns

XP – The matrix of features, where n_output_features is the number of features that would be returned from PolynomialFeatures.

Return type

array_like, shape (n_samples, n_features, n_output_features)