WeiChing 林煒清
WeiChing 林煒清

Reputation: 4469

what's the use of transformer_weights in scikit-learn pipeline?

It's just a little question of scikit-learn's pipeline.

In the class sklearn.pipeline.FeatureUnion , there is a transformer_weights option .

transformer_weights: dict, optional
: Multiplicative weights for features per transformer. Keys are transformer names, values the weights.

I saw the use in an example that give different weight to different feature.

    transformer_weights={
        'subject': 0.8,
        'body_bow': 0.5,
        'body_stats': 1.0,
    },

It's nonsense to me, because the classifier will learn the weighting for you later. Why bother using it at all?

Upvotes: 13

Views: 2721

Answers (1)

Andreas Mueller
Andreas Mueller

Reputation: 28748

If you use a linear classifier with penalty, this will change the amount of penalty applied to each block of features. Scaling features up will mean they will be less penalized relative to the other features.

Upvotes: 9

Related Questions