1
私はテキスト処理のためにscikit-learnを使用していますが、私のCountVectorizer
は期待した出力を得ていません。パンダのデータフレームを持つCountVectorizer
私のCSVファイルには、次のようになりますように
"Text";"label"
"Here is sentence 1";"label1"
"I am sentence two";"label2"
と。
だから、私はPythonのSVMの仕組みを理解するために、まずBag of Wordsを使いたいと思う。
import pandas as pd
from sklearn import svm
from sklearn.feature_extraction.text import CountVectorizer
data = pd.read_csv(open('myfile.csv'),sep=';')
target = data["label"]
del data["label"]
# Creating Bag of Words
count_vect = CountVectorizer()
X_train_counts = count_vect.fit_transform(data)
X_train_counts.shape
count_vect.vocabulary_.get(u'algorithm')
そして、私は
print(X_train_counts.shape)
を行うとき、私は文章で1048行を持っている間、私は、出力(1,1)
を参照してください。私は出力の見直しよりも
count_vect.vocabulary_.get(u'algorithm')
そしてこれはNone
です。
私が間違っていることを教えてもらえますか?私はthisチュートリアルに従っています。
なぜ、 'count_vect.vocabulary_.get(u'algorithm ')'が 'None'にならないのですか?この用語は、あなたの例ではどこにも定義されていません。 –
@aryamccarthy ok。それは理にかなっています。しかし、その形は何ですか? – ZverArt