調整模型係數
當你使用 scikit-learn 呼叫 fit 時,邏輯斯迴歸的係數會從你的資料集自動學得。在這個練習中,你將探索決策邊界如何由係數表示。為了達成這點,你會手動更改係數(而不是用 fit),並視覺化得到的分類器。
一個 2D 資料集已載入為環境中的 X 和 y,同時提供了一個線性分類器物件 model。
本練習屬於課程
Python 中的線性分類器
練習說明
- 將兩個係數與截距設定為不同數值,觀察得到的決策邊界。
- 試著建立直覺,了解係數如何影響決策邊界。
- 設定係數與截距,使模型在給定的訓練資料上不產生錯誤。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Set the coefficients
model.coef_ = np.array([[0,1]])
model.intercept_ = np.array([0])
# Plot the data and decision boundary
plot_classifier(X,y,model)
# Print the number of errors
num_err = np.sum(y != model.predict(X))
print("Number of errors:", num_err)