folie.functions.sklearnWrapper

class folie.functions.sklearnWrapper(estimator, domain, output_shape=(), expose_params=[])[source]

Wraps sklearn predictor as functions. Allow to use non parametric estimator for fit.

expose_params is a list of key for the parameters of the estimator to be exposed for optimisation

copy()[source]

Makes a deep copy of this function.

Returns:
copy

A new copy of this model.

fit(x, y=None, **kwargs)[source]

Fit coefficients of the function using linear regression. Use as features the derivative of the function with respect to the coefficients

Parameters:
X{array-like} of shape (n_samples, dim)
Point of evaluation of the training data
yarray-like of shape (n_samples,) or (n_samples, n_targets)
Target values. Will be cast to X’s dtype if necessary.
estimator: sklearn compatible estimator
Defaut to sklearn.linear_model.LinearRegression(copy_X=False, fit_intercept=False) but any compatible estimator can be used.
Estimator should have a coef_ attibutes after fitting
fit_transform(X, y=None, **fit_params)[source]

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:
Xarray-like of shape (n_samples, n_features)

Input samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).

**fit_paramsdict

Additional fit parameters.

Returns:
X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_params(deep=False)[source]

Get the parameters.

Returns:
paramsmapping of string to any

Parameter names mapped to their values.

grad_coeffs(x, *args, **kwargs)[source]

Gradient of the function with respect to the coefficients.

Parameters:
xarray_like

Input data.

Returns:
transformedarray_like

The gradient

resize(new_shape)[source]

Change the output shape of the function.

Parameters:
new_shapetuple, array-like

The new output shape of the function

set_output(*, transform=None)[source]

Set output container.

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

Parameters:
transform{“default”, “pandas”, “polars”}, default=None

Configure output of transform and fit_transform.

  • “default”: Default output format of a transformer

  • “pandas”: DataFrame output

  • “polars”: Polars output

  • None: Transform configuration is unchanged

Added in version 1.4: “polars” option was added.

Returns:
selfestimator instance

Estimator instance.

set_params(**params)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfobject

Estimator instance.

transform(X, *args, **kwargs)[source]

Transforms the input data.

transform_d2x(x, *args, **kwargs)[source]

Hessian of the function with respect to input data. Implemented by finite difference.

transform_dx(x, **kwargs)[source]

Gradient of the function with respect to input data. Implemented by finite difference.

property coefficients

Access the coefficients