시작하기무료로 시작하기

Twitter 데이터로 Logistic regression 수행하기

이번 연습에서는 tweets 데이터셋으로 로지스틱 회귀 모델을 구축합니다. 타깃 변수는 airline_sentiment이며, 부정 트윗은 0, 중립은 1, 긍정은 2입니다. 즉, 이번에는 다중 클래스 분류 과제입니다. 이진 분류에서 배운 내용은 다중 클래스 분류에도 그대로 적용됩니다.

슬라이드에서 소개한 두 가지 방법으로 모델의 정확도를 평가해 보세요.

로지스틱 회귀 함수와 정확도 점수 함수는 이미 임포트되어 있습니다.

이 연습은 강의의 일부입니다

Python으로 배우는 Sentiment Analysis

강의 보기

연습 안내

  • 정의된 Xy를 인자로 사용해 로지스틱 회귀 모델을 구축하고 학습(fit)하세요.
  • 로지스틱 회귀 모델의 정확도를 계산하세요.
  • 레이블을 예측하세요.
  • 예측 레이블과 실제 레이블을 사용해 accuracy score 를 계산하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Define the vector of targets and matrix of features
y = tweets.airline_sentiment
X = tweets.drop('airline_sentiment', axis=1)

# Build a logistic regression model and calculate the accuracy
log_reg = ____.____(X, y)
print('Accuracy of logistic regression: ', log_reg.____)

# Create an array of prediction
y_predict = log_reg.____

# Print the accuracy using accuracy score
print('Accuracy of logistic regression: ', ____(___, ____))
코드 편집 및 실행