邏輯斯迴歸 vs. 分類樹
分類樹會把特徵空間切分成「矩形區域」。相對地,像邏輯斯迴歸這樣的線性模型只會產生一條線性的決策邊界,把特徵空間劃分成兩個決策區域。
我們已提供一個自訂函式 plot_labeled_decision_regions(),你可以用它來繪製包含兩個已訓練分類器之清單的決策區域。你可以在終端機輸入 help(plot_labeled_decision_regions) 以瞭解更多關於此函式的資訊。
X_train、X_test、y_train、y_test、你先前練習中訓練好的模型 dt,以及函式 plot_labeled_decision_regions() 都已在你的工作環境中可用。
本練習屬於課程
Machine Learning with Tree-Based Models in Python
練習說明
從
sklearn.linear_model匯入LogisticRegression。建立一個
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)