adapt.feature_based.fMMD

class adapt.feature_based.fMMD(estimator=None, Xt=None, threshold='auto', kernel='linear', gamma=1.0, degree=2, coef=1.0, copy=True, verbose=1, random_state=None, **params)[source]

fMMD : feature Selection with MMD

LDM selects input features in order to minimize the maximum mean discrepancy (MMD) between the source and the target data.

Parameters
estimatorsklearn estimator or tensorflow Model (default=None)

Estimator used to learn the task. If estimator is None, a LinearRegression instance is used as estimator.

Xtnumpy array (default=None)

Target input data.

thresholdfloat or ‘auto’ (default=’auto’)

Threshold on features_scores_ all feature with score above threshold will be removed. If ‘auto’ the threshold is chosen to maximize the difference between scores of selected features and removed ones.

kernelstr (default=’linear’)

Choose the kernel between [‘linear’, ‘rbf’, ‘poly’]. The kernels are computed as follows:

  • kernel = linear:

    k(X, Y) = <X, Y>
    
  • kernel = rbf:

    k(X, Y) = exp(gamma * ||X-Y||^2)
    
  • kernel = poly:

    poly(X, Y) = (gamma * <X, Y> + coef)^degree
    
gammafloat (default=1.)

Gamma multiplier for the ‘rbf’ and ‘poly’ kernels.

degreeint (default=2)

Degree of the ‘poly’ kernel

coeffloat (default=1.)

Coef of the ‘poly’ kernel

copyboolean (default=True)

Whether to make a copy of estimator or not.

verboseint (default=1)

Verbosity level.

random_stateint (default=None)

Seed of random generator.

paramskey, value arguments

Arguments given at the different level of the adapt object. It can be, for instance, compile or fit parameters of the estimator or kernel parameters etc… Accepted parameters can be found by calling the method _get_legal_params(params).

See also

CORAL
FE

References

1

[1] S. Uguroglu and J. Carbonell. “Feature selection for transfer learning.” In ECML PKDD. 2011.

Examples

>>> from sklearn.linear_model import RidgeClassifier
>>> from adapt.utils import make_classification_da
>>> from adapt.feature_based import fMMD
>>> Xs, ys, Xt, yt = make_classification_da()
>>> model = fMMD(RidgeClassifier(), Xt=Xt, kernel="linear", random_state=0, verbose=0)
>>> model.fit(Xs, ys)
>>> model.score(Xt, yt)
0.45
Attributes
estimator_object

Estimator.

selected_features_numpy array

The selected features

features_scores_numpy array

The score attributed to each feature

Methods

__init__([estimator, Xt, threshold, kernel, ...])

fit(X, y[, Xt, yt, domains])

Fit Adapt Model.

fit_estimator(X, y[, sample_weight, ...])

Fit estimator on X, y.

fit_transform(Xs, Xt, **kwargs)

Fit embeddings.

get_params([deep])

Get parameters for this estimator.

predict(X[, domain])

Return estimator predictions after adaptation.

predict_estimator(X, **predict_params)

Return estimator predictions for X.

score(X, y[, sample_weight, domain])

Return the estimator score.

set_params(**params)

Set the parameters of this estimator.

transform(X)

Return the projection of X on the selected featues.

unsupervised_score(Xs, Xt)

Return unsupervised score.

__init__(estimator=None, Xt=None, threshold='auto', kernel='linear', gamma=1.0, degree=2, coef=1.0, copy=True, verbose=1, random_state=None, **params)[source]
fit(X, y, Xt=None, yt=None, domains=None, **fit_params)[source]

Fit Adapt Model.

For feature-based models, the transformation of the input features Xs and Xt is first fitted. In a second stage, the estimator_ is fitted on the transformed features.

For instance-based models, source importance weights are first learned based on Xs, ys and Xt. In a second stage, the estimator_ is fitted on Xs, ys with the learned importance weights.

Parameters
Xnumpy array

Source input data.

ynumpy array

Source output data.

Xtarray (default=None)

Target input data. If None, the Xt argument given in init is used.

ytarray (default=None)

Target input data. Only needed for supervised and semi-supervised Adapt model. If None, the yt argument given in init is used.

domainsarray (default=None)

Vector giving the domain for each source data. Can be used for multisource purpose.

fit_paramskey, value arguments

Arguments given to the fit method of the estimator.

Returns
selfreturns an instance of self
fit_estimator(X, y, sample_weight=None, random_state=None, warm_start=True, **fit_params)[source]

Fit estimator on X, y.

Parameters
Xarray

Input data.

yarray

Output data.

sample_weightarray

Importance weighting.

random_stateint (default=None)

Seed of the random generator

warm_startbool (default=True)

If True, continue to fit estimator_, else, a new estimator is fitted based on a copy of estimator. (Be sure to set copy=True to use warm_start=False)

fit_paramskey, value arguments

Arguments given to the fit method of the estimator and to the compile method for tensorflow estimator.

Returns
estimator_fitted estimator
fit_transform(Xs, Xt, **kwargs)[source]

Fit embeddings.

Parameters
Xsarray

Input source data.

Xtarray

Input target data.

kwargskey, value argument

Not used, present here for adapt consistency.

Returns
Xs_embembedded source data
get_params(deep=True)[source]

Get parameters for this estimator.

Parameters
deepbool, default=True

Not used, here for scikit-learn compatibility.

Returns
paramsdict

Parameter names mapped to their values.

predict(X, domain=None, **predict_params)[source]

Return estimator predictions after adaptation.

For feature-based method (object which implements a transform method), the input feature X are first transformed. Then the predict method of the fitted estimator estimator_ is applied on the transformed X.

Parameters
Xarray

input data

domainstr (default=None)

For antisymetric feature-based method, different transformation of the input X are applied for different domains. The domain should then be specified between “src” and “tgt”. If None the default transformation is the target one.

Returns
y_predarray

prediction of the Adapt Model.

predict_estimator(X, **predict_params)[source]

Return estimator predictions for X.

Parameters
Xarray

input data

Returns
y_predarray

prediction of estimator.

score(X, y, sample_weight=None, domain=None)[source]

Return the estimator score.

If the object has a transform method, the estimator is applied on the transformed features X. For antisymetric transformation, a parameter domain can be set to specified between source and target transformation.

Call score on sklearn estimator and evaluate on tensorflow Model.

Parameters
Xarray

input data

yarray

output data

sample_weightarray (default=None)

Sample weights

domainstr (default=None)

This parameter specifies for antisymetric feature-based method which transformation will be applied between “source” and “target”. If None the transformation by default is the target one.

Returns
scorefloat

estimator score.

set_params(**params)[source]

Set the parameters of this estimator.

Parameters
**paramsdict

Estimator parameters.

Returns
selfestimator instance

Estimator instance.

transform(X)[source]

Return the projection of X on the selected featues.

Parameters
Xarray

Input data.

Returns
X_embarray

Embeddings of X.

unsupervised_score(Xs, Xt)[source]

Return unsupervised score.

The normalized discrepancy distance is computed between the reweighted/transformed source input data and the target input data.

Parameters
Xsarray

Source input data.

Xtarray

Source input data.

Returns
scorefloat

Unsupervised score.

Examples