가장 긍정적인 단어와 부정적인 단어 찾기
이 연습 문제에서는 영화 리뷰 감성 데이터셋에 대해 학습한 로지스틱 회귀의 계수를 해석해 보겠습니다. 모델 객체는 이미 lr 변수에 인스턴스화되어 학습까지 완료되어 있어요.
또한 각 특성에 해당하는 단어들은 vocab 변수에 로드되어 있습니다. 예를 들어 vocab[100]이 "think"라면, 특성 100은 해당 영화 리뷰에서 단어 "think"가 등장한 횟수에 해당한다는 뜻입니다.
이 연습은 강의의 일부입니다
Python으로 배우는 선형 분류기
연습 안내
- 가장 큰 계수 5개에 해당하는 단어를 찾으세요.
- 가장 작은 계수 5개에 해당하는 단어를 찾으세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Get the indices of the sorted cofficients
inds_ascending = np.argsort(lr.coef_.flatten())
inds_descending = inds_ascending[::-1]
# Print the most positive words
print("Most positive words: ", end="")
for i in range(5):
print(____, end=", ")
print("\n")
# Print most negative words
print("Most negative words: ", end="")
for i in range(5):
print(____, end=", ")
print("\n")