텍스트 마이닝
감성 분석 (2)
정보전달자T
2023. 7. 17. 09:30
반응형
8.2 감성 사전을 이용한 영화 리뷰 감성 분석
8.2.3 AFINN을 이용한 감성 분석
- AFINN 어휘 목록은 덴마크의 핀 아럽 닐셀이 2009년부터 2011년까지 수작업으로 -5 에서 5 사이의 극성을 부여한 영어 단어들의 리스트
!pip install afinn
from afinn import Afinn
def sentiment_Afinn(docs):
afn = Afinn(emoticons=True)
results = []
for doc in docs:
if afn.score(doc) > 0:
results.append('pos')
else:
results.append('neg')
return results
print('#Afinn을 이용한 리뷰 감성분석의 정확도:', accuracy_score(categories, sentiment_Afinn(reviews)))
"""
/usr/local/lib/python3.10/dist-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
and should_run_async(code)
#Afinn을 이용한 리뷰 감성분석의 정확도: 0.664
"""
8.2.4 VADER를 이용한 감성 분석
import nltk
nltk.download('vader_lexicon')
!pip install vaderSentiment
from nltk.sentiment.vader import SentimentIntensityAnalyzer
def sentiment_vader(docs):
analyser = SentimentIntensityAnalyzer()
results = []
for doc in docs:
score = analyser.polarity_scores(doc)
if score['compound'] > 0:
results.append('pos')
else:
results.append('neg')
return results
print('#Vader을 이용한 리뷰 감성분석의 정확도:', accuracy_score(categories, sentiment_vader(reviews)))
"""
/usr/local/lib/python3.10/dist-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
and should_run_async(code)
#Vader을 이용한 리뷰 감성분석의 정확도: 0.635
"""
8.2.5 한글 감성사전
- 한글 문서에 대한 감성 분석을 위해 한글 감성사전이 필요함
- KNU 감성사전
- 감성 분석 결과 라이브러리 KoreanSentimentAnalyze
※ 해당 내용은 <파이썬 텍스트 마이닝 완벽 가이드>의 내용을 토대로 학습하며 정리한 내용입니다.
반응형