def fit_classifier(feat_dicts=None, y_true=None, weights=None):
# clf = MultinomialNB()
clf = LogisticRegression(class_weight='balanced')
pipeline = Pipeline([
('vectorizer', DictVectorizer()),
('selection', VarianceThreshold()),
('classifier', clf)
])
# cf. http://stackoverflow.com/questions/36205850/sklearn-pipeline-applying-sample-weights-after-applying-a-polynomial-feature-t
pipeline.fit(feat_dicts, y_true, **{'classifier__sample_weight': weights})
return pipeline
评论列表
文章目录