特征抽取---countVectorizer

特征抽取---countVectorizer

#!/usr/bin/python
# -*- coding:utf-8 -*-
from sklearn.feature_extraction.text import CountVectorizer,TfidfVectorizer
from sklearn.feature_extraction import DictVectorizer

def countvec():
    list1=["hello world hello hello","hello tom","hello lucy","tom lucy"]
    countvec=CountVectorizer()
    list1=countvec.fit_transform(list1)
    print(countvec.get_feature_names())
    # print(list1)
    print(list1.toarray())
    pass

if __name__ == '__main__':
    print("hello")
    countvec()

 

你可能感兴趣的:(机器学习)