我正在研究一个文本分类模型,并使用
Pipeline
外加
GridSearch Cross Validation
.下面的代码段:
count_vec=CountVectorizer(ngram_range=(1,2),stop_words=Stopwords_X,min_df=0.01)
TFIDF_Transformer=TfidfTransformer(sublinear_tf=True,norm='l2')
my_pipeline=Pipeline([('Count_Vectorizer',count_vec),
('TF_IDF',TFIDF_Transformer),
('MultiNomial_NB',MultinomialNB())])
param_grid={'Count_Vectorizer__ngram_range':[(1,1),(1,2),(2,2)],
'Count_Vectorizer__stop_words':[Stopwords_X,stopwords],
'Count_Vectorizer__min_df':[0.001,0.005,0.01],
'TF_IDF__sublinear_tf':[True,False],
'TF_IDF__norm':['l2'],
'TF_IDF__smooth_idf':[True,False],
'MultiNomial_NB__alpha':[0.2,0.4,0.5,0.6],
'MultiNomial_NB__fit_prior':[True,False]}
# Grid Search CV with pipeline
model=GridSearchCV(estimator=my_pipeline,param_grid=param_grid,
scoring=scoring,cv=4,verbose=1,refit=False)
然而
,由于数据高度不平衡,我想将权重传递给
MultinomialNB
管道中的分类器。我知道我可以将权重传递给管道内的元素(如下所示):
model.fit(Data_Labeled['Clean-Merged-Final'],
Data_Labeled['Labels'],MultiNomial_NB__sample_weight=weights)
我的问题是,如何在没有形状错误的情况下进行编译?
因为权重只传递给管道中的最终元素(多项式\u NB分类器),而CV对进入管道的X/Y馈送进行分区。