【发布时间】:2016-02-12 20:57:00
【问题描述】:
我正在使用 scikit-learn 创建文档的特征向量。 我的目标是用这些特征向量创建一个二元分类器(Genderclassifier)。
我希望将 k-top Words 作为特征,因此两个标签文档中的 k 个最高计数词(k=10 -> 20 个特征,因为 2 个标签)
我的两个文档(label1document、label2document)都充满了这样的实例:
user:somename, post:"A written text which i use"
到目前为止,我的理解是,我使用两个文档中所有实例的所有文本来创建一个带有计数的词汇表(两个标签的计数,以便我可以比较标签数据):
#These are my documents with all text
label1document = "car eat essen sleep sleep"
label2document = "eat sleep woman woman woman woman"
vectorizer = CountVectorizer(min_df=1)
corpus = [label1document,label2document]
#Here I create a Matrix with all the countings of the words from both documents
X = vectorizer.fit_transform(corpus)
问题1:我必须在 fit_transform 中放入什么才能从两个标签中获得最多计数的单词?
X_new = SelectKBest(chi2, k=2).fit_transform( ?? )
因为最后,我想要这样的训练数据(实例):
<label> <feature1 : value> ... <featureN: value>
问题 2:我如何从那里获取这些训练数据?
奥利弗
【问题讨论】:
标签: python machine-learning scikit-learn svm feature-selection