adapt.parameter_based.TransferTreeClassifier
- class adapt.parameter_based.TransferTreeClassifier(estimator=None, Xt=None, yt=None, algo='', copy=True, verbose=1, random_state=None, **params)[source]
TransferTreeClassifier: Modify a source Decision tree on a target dataset.
- Parameters
- estimatorsklearn DecsionTreeClassifier (default=None)
Source decision tree classifier.
- Xtnumpy array (default=None)
Target input data.
- ytnumpy array (default=None)
Target output data.
- algostr or callable (default=””)
Leaves relabeling if “” or “relab”. “ser” and “strut” for SER and STRUT algorithms
- copyboolean (default=True)
Whether to make a copy of
estimatoror not.- verboseint (default=1)
Verbosity level.
- random_stateint (default=None)
Seed of random generator.
References
- 1
[1] Segev, Noam and Harel, Maayan Mannor, Shie and Crammer, Koby and El-Yaniv, Ran “Learn on Source, Refine on Target: A Model Transfer Learning Framework with Random Forests”. In IEEE TPAMI, 2017.
- 2
[2] Minvielle, Ludovic and Atiq, Mounir Peignier, Sergio and Mougeot, Mathilde “Transfer Learning on Decision Tree with Class Imbalance”. In IEEE ICTAI, 2019.
Examples
>>> from adapt.utils import make_classification_da >>> from sklearn.tree import DecisionTreeClassifier >>> from adapt.parameter_based import TransferTreeClassifier >>> Xs, ys, Xt, yt = make_classification_da() >>> src_model = DecisionTreeClassifier().fit(Xs, ys) >>> src_model.score(Xt, yt) 0.62 >>> tgt_model = TransferTreeClassifier(src_model) >>> tgt_model.fit(Xt[[1, -1]], yt[[1, -1]]) >>> tgt_model.score(Xt, yt) 0.92
- Attributes
- estimator_sklearn DecsionTreeClassifier
Transferred decision tree classifier using target data.
- parentsnumpy array of int.
- bool_parents_lrnumpy array of {-1,0,1} values.
- pathsnumpy array of int arrays.
- rulesnumpy array of 3-tuple arrays.
- depthsnumpy array of int.
Methods
__init__([estimator, Xt, yt, algo, copy, ...])extend(node, subtree)fit([Xt, yt])Fit TransferTreeClassifier.
fit_estimator(X, y[, sample_weight, ...])Fit estimator on X, y.
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.
prune(node[, include_node, lr, leaf_value])score(X, y[, sample_weight, domain])Return the estimator score.
set_params(**params)Set the parameters of this estimator.
swap_subtrees(node1, node2)unsupervised_score(Xs, Xt)Return unsupervised score.
updateSplit(node, feature, threshold)updateValue(node, values)- __init__(estimator=None, Xt=None, yt=None, algo='', copy=True, verbose=1, random_state=None, **params)[source]
- fit(Xt=None, yt=None, **fit_params)[source]
Fit TransferTreeClassifier.
- Parameters
- Xtnumpy array (default=None)
Target input data.
- ytnumpy array (default=None)
Target output data.
- fit_paramskey, value arguments
Not used. Here for sklearn compatibility.
- 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 ofestimator. (Be sure to setcopy=Trueto usewarm_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
- 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
transformmethod), the input featureXare first transformed. Then thepredictmethod of the fitted estimatorestimator_is applied on the transformedX.- 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
Nonethe 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
transformmethod, 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
Nonethe 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.