0

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 개의 분류 자 ​​조합 모두에 대해 정의 할 필요없이 어떻게 할 수 있습니까?

답변

1

나는

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_c‌​lf).fit(train_wordlis‌​t, train_property_label‌​s_threshold) 
+0

를 사용할 수 있습니다. 왜냐하면 나는 16 개 이상의 모델을 위해 해당 라인을 복사해야하기 때문이다. –

+0

그리고 1,2,3 등을 사용한다. –

+0

추적 코드를 게시한다. – marmouset