adapt.parameter_based.LinInt

classadapt.parameter_based.LinInt(estimator=None,Xt=None,yt=None,prop=0.5,copy=True,verbose=1,random_state=None,**params)[source]

LinInt: Linear Interpolation between SrcOnly and TgtOnly.

LinInt linearly interpolates the predictions of the SrcOnly andTgtOnly models. The interpolation parameter is adjusted based ona small amount of target data removed from the training setof TgtOnly.

Parameters
estimatorsklearn estimator or tensorflow Model (default=None)

Estimator used to learn the task. If estimator isNone, aLinearRegressioninstance is used as estimator.

Xtnumpy array (default=None)

Target input data.

ytnumpy array (default=None)

Target output data.

propfloat (default=0.5)

Proportion between 0 and 1 of the data usedto fit the TgtOnly model. The rest of the target data are used to estimate the interpolationparameter.

copyboolean (default=True)

Whether to make a copy ofestimator 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 theestimator or kernel parameters etc…Accepted parameters can be found by calling the method_get_legal_params(params).

References

1

[1] Daume III, H. “Frustratingly easy domain adaptation”. In ACL, 2007.

Examples

>>>fromsklearn.linear_modelimportRidge>>>fromadapt.utilsimportmake_regression_da>>>fromadapt.parameter_basedimportLinInt>>>Xs,ys,Xt,yt=make_regression_da()>>>model=LinInt(Ridge(),Xt=Xt[:6],yt=yt[:6],prop=0.5,...verbose=0,random_state=0)>>>model.fit(Xs,ys)>>>model.score(Xt,yt)0.68...
Attributes
estimator_src_object

Fitted source estimator.

estimator_object

Fitted estimator.

Methods

__init__([estimator, Xt, yt, prop, copy, ...])

fit(Xs, ys[, Xt, yt])

Fit LinInt.

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

Fit estimator on X, y.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

predict(X)

Return LinInt predictions.

predict_estimator(X, **predict_params)

Return estimator predictions for X.

score(X, y)

Compute R2 score

set_fit_request(*[, Xs, ys])

Request metadata passed to thefit method.

set_params(**params)

Set the parameters of this estimator.

set_predict_request(*[, domain])

Request metadata passed to thepredict method.

set_score_request(*[, domain, sample_weight])

Request metadata passed to thescore method.

unsupervised_score(Xs, Xt)

Return unsupervised score.

__init__(estimator=None,Xt=None,yt=None,prop=0.5,copy=True,verbose=1,random_state=None,**params)[source]
fit(Xs,ys,Xt=None,yt=None,**kwargs)[source]

Fit LinInt.

Parameters
Xsarray

Source input data.

ysarray

Source output data.

Xtarray

Target input data.

ytarray

Target output data.

kwargskey, value argument

Not used, present here for adapt consistency.

Returns
Xt_aug, ytaugmented input and output target data
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 fitestimator_,else, a new estimator is fitted based ona copy ofestimator. (Be sure to setcopy=True to usewarm_start=False)

fit_paramskey, value arguments

Arguments given to the fit method ofthe estimator and to the compile methodfor tensorflow estimator.

Returns
estimator_fitted estimator
get_metadata_routing()[source]

Get metadata routing of this object.

Please checkUser Guide on how the routingmechanism works.

Returns
routingMetadataRequest

AMetadataRequest encapsulatingrouting information.

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)[source]

Return LinInt predictions.

Parameters
Xarray

Input data.

Returns
yarray

Predictions

predict_estimator(X,**predict_params)[source]

Return estimator predictions for X.

Parameters
Xarray

input data

Returns
y_predarray

prediction of estimator.

score(X,y)[source]

Compute R2 score

Parameters
Xarray

input data

yarray

output data

Returns
scorefloat

estimator score.

set_fit_request(*,Xs:Union[bool,None,str]='$UNCHANGED$',ys:Union[bool,None,str]='$UNCHANGED$')adapt.parameter_based._linint.LinInt[source]

Request metadata passed to thefit method.

Note that this method is only relevant ifenable_metadata_routing=True (seesklearn.set_config()).Please seeUser Guide on how the routingmechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed tofit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it tofit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains theexisting request. This allows you to change the request for someparameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as asub-estimator of a meta-estimator, e.g. used inside aPipeline. Otherwise it has no effect.

Parameters
Xsstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing forXs parameter infit.

ysstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing forys parameter infit.

Returns
selfobject

The updated object.

set_params(**params)[source]

Set the parameters of this estimator.

Parameters
**paramsdict

Estimator parameters.

Returns
selfestimator instance

Estimator instance.

set_predict_request(*,domain:Union[bool,None,str]='$UNCHANGED$')adapt.parameter_based._linint.LinInt[source]

Request metadata passed to thepredict method.

Note that this method is only relevant ifenable_metadata_routing=True (seesklearn.set_config()).Please seeUser Guide on how the routingmechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed topredict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it topredict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains theexisting request. This allows you to change the request for someparameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as asub-estimator of a meta-estimator, e.g. used inside aPipeline. Otherwise it has no effect.

Parameters
domainstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing fordomain parameter inpredict.

Returns
selfobject

The updated object.

set_score_request(*,domain:Union[bool,None,str]='$UNCHANGED$',sample_weight:Union[bool,None,str]='$UNCHANGED$')adapt.parameter_based._linint.LinInt[source]

Request metadata passed to thescore method.

Note that this method is only relevant ifenable_metadata_routing=True (seesklearn.set_config()).Please seeUser Guide on how the routingmechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed toscore if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it toscore.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains theexisting request. This allows you to change the request for someparameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as asub-estimator of a meta-estimator, e.g. used inside aPipeline. Otherwise it has no effect.

Parameters
domainstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing fordomain parameter inscore.

sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing forsample_weight parameter inscore.

Returns
selfobject

The updated object.

unsupervised_score(Xs,Xt)[source]

Return unsupervised score.

The normalized discrepancy distance is computedbetween the reweighted/transformed source inputdata and the target input data.

Parameters
Xsarray

Source input data.

Xtarray

Source input data.

Returns
scorefloat

Unsupervised score.

Examples