在我的(IID)数据集的每个样本是这样的:
X = [A_1,A_2 ... A_N,B_1,B_2 ... B_M]
我也有各样品的标签(这是监督学习)
的一个特征是非常稀疏的(即袋的字表示),而b特征是致密的(整数,疗法e是〜45的那些)
我正在使用scikit-learn,并且我想在管道中使用GridSearchCV。
的问题:是否有可能对功能型一个和另一CountVectorizer上的功能型b使用一个CountVectorizer?
我想可以看作:
pipeline = Pipeline([
('vect1', CountVectorizer()), #will work only on features [0,(N-1)]
('vect2', CountVectorizer()), #will work only on features [N,(N+M-1)]
('clf', SGDClassifier()), #will use all features to classify
])
parameters = {
'vect1__max_df': (0.5, 0.75, 1.0), # type a features only
'vect1__ngram_range': ((1, 1), (1, 2)), # type a features only
'vect2__max_df': (0.5, 0.75, 1.0), # type b features only
'vect2__ngram_range': ((1, 1), (1, 2)), # type b features only
'clf__alpha': (0.00001, 0.000001),
'clf__penalty': ('l2', 'elasticnet'),
'clf__n_iter': (10, 50, 80),
}
grid_search = GridSearchCV(pipeline, parameters, n_jobs=-1, verbose=1)
grid_search.fit(X, y)
这可能吗?
A nice idea由@Andreas Mueller提交。然而,我想保留原始的非选择功能,因此,我不能告诉管道前期(管道开始前)的每个阶段的列索引。
例如,如果我设置了CountVectorizer(max_df=0.75)
,它可能会减少一些项,并且原始列索引将会更改。
谢谢
嗨,我读了你附加和编辑我的原始,随时回应。 – omerbp
您需要使用FeatureUnion并行提取多个要素。 –
是的,并把它作为管道中的第一个地方....应该花一些时间来构建它。然而,正如我所看到的那样 - 我不能使用FeatureSelector,因为我想要做两次选择 - 一次是针对每种特征类型的,对吧? – omerbp