当前位置 : 主页 > 编程语言 > python >

Scikit Learn CountVectorizer 入门实例

来源:互联网 收集:自由互联 发布时间:2022-07-20
​​http://stackoverflow.com/questions/27488446/scikit-learn-countvectorizer​​ from sklearn.feature_extraction.text import CountVectorizer texts=["dog cat fish","dog cat cat","fish bird", 'bird'] cv = CountVectorizer() cv_fit=cv.fit_t


​​http://stackoverflow.com/questions/27488446/scikit-learn-countvectorizer​​

from sklearn.feature_extraction.text import CountVectorizer

texts=["dog cat fish","dog cat cat","fish bird", 'bird']
cv = CountVectorizer()
cv_fit=cv.fit_transform(texts)

print(cv.get_feature_names())
print(cv_fit.toarray())
#['bird', 'cat', 'dog', 'fish']
#[[0 1 1 1]
# [0 2 1 0]
# [1 0 0 1]
# [1 0 0 0]]

print(cv_fit.toarray().sum(axis=0))
#[2 3 2 2]


上一篇:Java-Python的完全对齐的tokenizer(字级别)
下一篇:没有了
网友评论