n00b
n00b

Reputation: 1639

How to give different weights to features while training a SGDClassifier in Scikit?

From the documentation,

class sklearn.linear_model.SGDClassifier(class_weight=None)

Like the class_weight function, how do I give weights to particular aspects of my feature set? Like my feature sets consists of raw text, and some name. While training I want to give more weight to name, and less weight to the raw text. How do I do that?

Upvotes: 2

Views: 1453

Answers (1)

MB-F
MB-F

Reputation: 23637

There is no option to give weights to features in SGDClassifier, and as far I know in no other learner in scikit-learn.

In general, it does not make sense to give different weights to features. After all, you do machine learning because you want the computer to figure out which features are more important. If name is more important than raw text the classifier will figure that out internally.

Now, if you still want to have different features with different importance you can combine multiple classifiers: Train one classifier using only the name feature, and train another classifier using only raw text features. Then combine their output by taking the weighted average of each classifier's output. You can give the name-classifier a higher weight, which will increase name's impact on the combined output.

Upvotes: 2

Related Questions