Logistic regression เทียบกับ classification tree
Classification tree จะแบ่งพื้นที่ฟีเจอร์ออกเป็นบริเวณสี่เหลี่ยม ในทางตรงข้าม โมเดลเชิงเส้นอย่าง logistic regression จะสร้างเส้นแบ่งการตัดสินใจเพียงเส้นเดียว ซึ่งแบ่งพื้นที่ฟีเจอร์ออกเป็นสองบริเวณ
เราได้เขียนฟังก์ชันชื่อ plot_labeled_decision_regions() ไว้ให้แล้ว ฟังก์ชันนี้ใช้สำหรับพล็อตบริเวณการตัดสินใจของรายการที่ประกอบด้วย classifier ที่ฝึกแล้วสองตัว สามารถพิมพ์ help(plot_labeled_decision_regions) ใน shell เพื่อดูรายละเอียดเพิ่มเติม
X_train, X_test, y_train, y_test, โมเดล dt ที่ฝึกไว้ในแบบฝึกหัดก่อนหน้า รวมถึงฟังก์ชัน plot_labeled_decision_regions() พร้อมใช้งานใน workspace แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Machine Learning with Tree-Based Models in Python
คำแนะนำการฝึกหัด
นำเข้า
LogisticRegressionจากsklearn.linear_modelสร้างอินสแตนซ์ของโมเดล
LogisticRegressionแล้วกำหนดให้กับตัวแปรlogregฝึกโมเดล
logregด้วยชุดข้อมูลฝึกตรวจสอบกราฟที่สร้างโดย
plot_labeled_decision_regions()
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Import LogisticRegression from sklearn.linear_model
from ____.____ import ____
# Instatiate logreg
____ = ____(random_state=1)
# Fit logreg to the training set
____.____(____, ____)
# Define a list called clfs containing the two classifiers logreg and dt
clfs = [logreg, dt]
# Review the decision regions of the two classifiers
plot_labeled_decision_regions(X_test, y_test, clfs)