【发布时间】:2016-12-24 04:02:02
【问题描述】:
我有一个 Pipeline 对象,我想将其放入训练和测试标签的不同组合中,因此使用 fit 对象创建不同的预测。但我相信fit 使用相同的分类器对象会摆脱以前的fit 对象。
我的代码示例是:
text_clf = Pipeline([('vect', CountVectorizer(analyzer="word",tokenizer=None,preprocessor=None,stop_words=None,max_features=5000)),
('tfidf', TfidfTransformer(use_idf=True,norm='l2',sublinear_tf=True)),
('clf',LogisticRegression(solver='newton-cg',class_weight='balanced', multi_class='multinomial',fit_intercept=True),
)])
print "Fitting the open multinomial BoW logistic regression model for probability models...\n"
open_multi_logit_words = text_clf.fit(train_wordlist, train_property_labels)
print "Fitting the open multinomial BoW logistic regression model w/ ",threshold," MAPE threshold...\n"
open_multi_logit_threshold_words = (text_clf.copy.deepcopy()).fit(train_wordlist, train_property_labels_threshold)
但是,分类器对象没有deepcopy() 方法。如何在无需定义的情况下实现我所需要的:
text_clf_open_multi_logit = Pipeline([('vect', CountVectorizer(analyzer="word",tokenizer=None,preprocessor=None,stop_words=None,max_features=5000)),
('tfidf', TfidfTransformer(use_idf=True,norm='l2',sublinear_tf=True)),
('clf',LogisticRegression(solver='newton-cg',class_weight='balanced', multi_class='multinomial',fit_intercept=True),
)])
对于我所有的 16 个分类器组合?
【问题讨论】:
标签: python scikit-learn logistic-regression text-classification