如何将TfIdfvectorizer与其余列结合

时间:2019-05-10 14:33:57

标签: python pipeline heterogeneous

我正在尝试在Python的一列上运行Tf-Idf,并希望将输出与数据框中的其余列结合起来,以将其提供给分类器。我已经将Feature Union与异构数据一起使用,但是由于某些原因,我一直在出错。我正在使用以下代码:

iwalk(obj, ~save(.x, paste0(path, folder, .y, ".RDa")))

我一直收到以下错误:

pipecols1=[col for col in dftrf.columns if col!='Name_x']
pipecols2=['Name_x']

class MySelector(BaseEstimator, TransformerMixin):
  def __init__(self, key):
    self.key = key

  def fit(self, x, y=None):
    return self

  def transform(self, data_dict):
    return data_dict[self.key]

var=  Pipeline([
                ('var', MySelector(key=pipecols1))])

text= Pipeline([
                ('text', MySelector(key=pipecols2) ),
                ('tfidf', TfidfVectorizer())])

feats = FeatureUnion(transformer_list=[('var',var),
                      ('text',text)],transformer_weights= 
{'var':1,'text':1})

feature_processing = Pipeline([('feats', feats)])

feature_processing.fit(x,y)

pipecols2是我的文本列 pipecols1是我要合并而不进行转换的列

有什么想法吗?

0 个答案:

没有答案