영화 리뷰 감성 분석
이 연습 문제에서는 Large Movie Review Dataset의 일부에 대해 로지스틱 회귀가 출력하는 확률을 살펴보겠습니다.
변수 X와 y는 이미 환경에 로드되어 있어요. X에는 영화 리뷰에서 단어가 등장한 횟수에 기반한 특징이 들어 있고, y에는 리뷰의 감성이 긍정(+1)인지 부정(-1)인지에 대한 레이블이 들어 있습니다.
이 연습은 강의의 일부입니다
Python으로 배우는 선형 분류기
연습 안내
- 영화 리뷰 데이터에 로지스틱 회귀 모델을 학습하세요.
- 주어진 두 리뷰에 대해 부정 vs. 긍정일 확률을 예측하세요.
- 직접 리뷰를 작성해 보고 그에 대한 확률도 확인해 보셔도 됩니다!
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Instantiate logistic regression and train
lr = ____
lr.fit(____)
# Predict sentiment for a glowing review
review1 = "LOVED IT! This movie was amazing. Top 10 this year."
review1_features = get_features(review1)
print("Review:", review1)
print("Probability of positive review:", lr.predict_proba(____)[0,1])
# Predict sentiment for a poor review
review2 = "Total junk! I'll never watch a film by that director again, no matter how good the reviews."
review2_features = get_features(review2)
print("Review:", review2)
print("Probability of positive review:", lr.predict_proba(____)[0,1])