시작하기무료로 시작하기

SGDClassifier 사용하기

이번 마지막 코딩 연습에서는 SGDClassifier()를 사용해 정규화 강도와 손실 함수(로지스틱 회귀 vs. 선형 SVM)에 대해 하이퍼파라미터 탐색을 수행해 볼 거예요.

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

Python으로 배우는 선형 분류기

강의 보기

연습 안내

  • random_state=0으로 SGDClassifier 인스턴스를 생성하세요.
  • 정규화 강도와 hingelog_loss 손실 함수를 대상으로 탐색하세요.

실습형 인터랙티브 연습

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

# We set random_state=0 for reproducibility 
linear_classifier = ____(random_state=0)

# Instantiate the GridSearchCV object and run the search
parameters = {'alpha':[0.00001, 0.0001, 0.001, 0.01, 0.1, 1], 
             'loss':[____]}
searcher = GridSearchCV(linear_classifier, parameters, cv=10)
searcher.fit(X_train, y_train)

# Report the best parameters and the corresponding score
print("Best CV params", searcher.best_params_)
print("Best CV accuracy", searcher.best_score_)
print("Test accuracy of best grid search hypers:", searcher.score(X_test, y_test))
코드 편집 및 실행