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 compativle with the expectations of NonparametricTwoStageLeastSquares’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 (integer, default = 2) – The degree of the polynomial features.

  • interaction_only (boolean, 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 (boolean, 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]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__([degree, interaction_only, …])

Initialize self.

fit(X[, y])

Compute number of output features.

fit_transform(X[, y])

Fit to data, then transform it.

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)

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)