为不同的拟合模型重用逻辑回归对象
Reuse a logistic regression object for different fitted models
我有一个 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 个分类器组合?
我会试试
text_clf0=copy.deepcopy(text_clf)
open_multi_logit_threshold_words = text_clf0.fit(train_wordlist, train_property_labels_threshold)
编辑:您可以使用列表
text_clf_list=[copy.deepcopy(text_clf) for _ in range(16)]
或直接
copy.deepcopy(text_clf).fit(train_wordlist, train_property_labels_threshold)
我有一个 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 个分类器组合?
我会试试
text_clf0=copy.deepcopy(text_clf)
open_multi_logit_threshold_words = text_clf0.fit(train_wordlist, train_property_labels_threshold)
编辑:您可以使用列表
text_clf_list=[copy.deepcopy(text_clf) for _ in range(16)]
或直接
copy.deepcopy(text_clf).fit(train_wordlist, train_property_labels_threshold)