sklearnでいくつかの文章を分類したいと思います。文章はパンダのデータフレームに保存されます。開始するに異なるフィーチャディメンションを持つFeatureUnion
、私は文の長さを使用したい、それが機能としてTF-IDFベクトルですので、私は、このパイプラインを作成しました:
LengthAnalyzerを持つカスタムTransformerMixin
ある
pipeline = Pipeline([
('features', FeatureUnion([
('meta', Pipeline([
('length', LengthAnalyzer())
])),
('bag-of-words', Pipeline([
('tfidf', TfidfVectorizer())
]))
])),
('model', LogisticRegression())
:
def transform(self, documents):
for document in documents:
yield len(document)
したがって、TfidfVectorizerがn次元のリストを返す間、LengthAnalyzerは数値(1次元)を返します。
私はこれを実行しようとすると、私はこの機能の組み合わせを動作させるために行われなければならない何
ValueError: blocks[0,:] has incompatible row dimensions. Got blocks[0,1].shape[0] == 494, expected 1.
を取得しますか?
1つの数値を2次元の形状の配列に変換します。[1,1] –
np.array(len(document))と同じです。reshape(-1,1)?同じエラー – Mirco