เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การใช้ SGDClassifier

ในแบบฝึกหัด Coding สุดท้ายนี้ จะได้ทำการค้นหา hyperparameter สำหรับความแข็งแกร่งของ regularization และ loss (logistic regression เทียบกับ linear SVM) โดยใช้ SGDClassifier()

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Linear Classifiers ใน Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • สร้างอินสแตนซ์ของ SGDClassifier โดยกำหนด random_state=0
  • ค้นหาค่าความแข็งแกร่งของ regularization และเปรียบเทียบ loss แบบ hinge กับ log_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))
แก้ไขและรันโค้ด