Mat*_*ien 1 python scikit-learn
我了解可以在Python的Scikit-learn包中创建计数矢量化程序时指定最小频率。但是,我想知道是否只有您不提供先验字典才是这种情况?当我提供自己的自定义词汇表(列表)时,此参数似乎不起作用。
为了弄清楚这一点,我重新阅读了该min_df参数的文档:
Parameters :
min_df : float in range [0.0, 1.0] or int, optional, 1 by default
When building the vocabulary, ignore terms that have a term frequency strictly lower than the given threshold.
This value is also called cut-off in the literature.
If float, the parameter represents a proportion of documents, integer absolute counts. This parameter is ignored if vocabulary is not None.
Run Code Online (Sandbox Code Playgroud)
就我而言,我向CountVectorizer提供了一个自定义词汇表,该词汇表由我之前获得的我自己的术语组成。
cv = CountVectorizer(vocabulary=my_own_terms, min_df=3)
X = cv.fit_transform(a_big_corpus)
Run Code Online (Sandbox Code Playgroud)
在查看输出时,我得到了出现一次,两次等的各种术语。
是否有人在工作中发生过这种情况?如果是这样,是否有可能的解决方案?提前致谢。
通过提供词汇表,这意味着您恰好需要该词汇表。即使一个术语在要转换的文本中仅出现一次或根本不出现,其他任何都无所谓。否则,它与您的确切意图(通过提供vocabulary参数)相矛盾,即您想要的正是该组词汇。因此,min_df根据文档,应该忽略约束是合理的。
根据您的后续评论,您似乎想要的是:
我想“完全”地使用我的词汇中的那些项目,但是如果一个单词只出现一次,那么我就不要了。
这基本上意味着您希望提取的词汇集中的术语足够频繁地出现。换句话说,您实际上并不真正想要这些词汇。我可能会这样:
CounterVectorizer您的数据提供全新的解决方案。CountVectorizer使用第2步中相交的词汇构造进行实际转换的实际值。您的方法直接跳到了步骤3,这就是矢量化器无法按您预期的那样工作的原因。
| 归档时间: |
|
| 查看次数: |
749 次 |
| 最近记录: |