## 아래와 같이 규칙 생성 ##
from sklearn.feature_extraction.text import CountVectorizer
vect = CountVectorizer(tokenizer=None, stop_words="english", analyzer='word').fit(특정리스트)
# tokenizer = 텍스트 데이터가 들어왔을 때 어떻게 단어를 나눠줄 지 정의
#(default일 경우 None, 한국어의 경우 별도 지정하여 기입 필요)
# stop_words = 불용어
#(영어의 경우 into, the, he "english"로 설정하면 됨/ 한국어의 경우 은는이가, 그)
#analyzer = 분석 단위
bow_vect = vect.fit_transform(특정리스트)
word_list = vect.get_featurenames() #각각 벡터들의 공간에 어떤 단어들이 들어가 있는지 알 수 있음.
count_list = bow_vect.toarray().sum(axis=0) #word_list에 있는 단어(각 벡터)들이 나온 횟수
## 규칙 생성 완료 ##
# 점검 ##
bow_vect.shape
bow_vect.toarray()
bow_vect.toarray().sum(axis=0) #count_list 한 것과 같은 결과 나옴. 각 열의 합으로 계산됨.
## 응용 1 ##
word_count_dict = dict(zip(word_list, count_list))
print(str(word_count_dict))[:50]
## 응용 2 (1에서 만든 dict 활용) ##
import operator
sorted(word_count_dict.items(), keys=operator.itemgetter(1),reverse=True)
#item을 정열기준을 뒤에 있는 횟수 기준으로, reverse True로 놓고 많은 순으로
## 시각화 ##
plt.hist(list(word_count_dict.values()), bins = 150)