[scikit-learn] Question about get_params / set_params

Guillaume Lemaître g.lemaitre58 at gmail.com
Sun Oct 28 05:37:57 EDT 2018


On Sun, 28 Oct 2018 at 09:31, Louis Abraham via scikit-learn <
scikit-learn at python.org> wrote:

> Hi,
>
> According to
> http://scikit-learn.org/0.16/developers/index.html#get-params-and-set-params
> ,
> get_params and set_params are used to clone estimators.
>

sklearn.base.clone is function used for cloning. get_params and set_params
are accessors to attributes of an estimator and are defined by
BaseEstimator.
For Pipeline and FeatureUnion, those accessors rely on the _BaseComposition
which manage the access to attributes to the sub-estimators.


> However, I don't understand how it is used in FeatureUnion:
> `return self._get_params('transformer_list', deep=deep)`
>

transformer_list contain all the estimators used in the FeatureUnion, and
the _BaseComposition allow you to access the parameters of each transformer.


>
> Why doesn't it contain other arguments like n_jobs and transformer_weights?
>

The first line in _get_params in _BaseCompositin will list the attributes
of FeatureUnion;
https://github.com/scikit-learn/scikit-learn/blob/06ac22d06f54353ea5d5bba244371474c7baf938/sklearn/utils/metaestimators.py#L26

For instance:

In [5]: trans = FeatureUnion([('trans1', StandardScaler()), ('trans2',
MinMaxScaler())])


In [6]:
trans.get_params()

Out[6]:
{'n_jobs': None,
 'transformer_list': [('trans1',
   StandardScaler(copy=True, with_mean=True, with_std=True)),
  ('trans2', MinMaxScaler(copy=True, feature_range=(0, 1)))],
 'transformer_weights': None,
 'trans1': StandardScaler(copy=True, with_mean=True, with_std=True),
 'trans2': MinMaxScaler(copy=True, feature_range=(0, 1)),
 'trans1__copy': True,
 'trans1__with_mean': True,
 'trans1__with_std': True,
 'trans2__copy': True,
 'trans2__feature_range': (0, 1)}

Then, n_jobs and transformer_weights are accessible.


>
> Best
> Louis
>
> _______________________________________________
> scikit-learn mailing list
> scikit-learn at python.org
> https://mail.python.org/mailman/listinfo/scikit-learn
>


-- 
Guillaume Lemaitre
INRIA Saclay - Parietal team
Center for Data Science Paris-Saclay
https://glemaitre.github.io/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-learn/attachments/20181028/aa504788/attachment.html>


More information about the scikit-learn mailing list