變動的係數
在了解 LogisticRegression() 模型的係數之後,進一步觀察當用不同欄位來訓練時,係數會如何改變。不同模型之間,欄位的係數會改變嗎?
你需要在不同的欄位群組上各自 .fit() 兩個 LogisticRegression() 模型來檢查。同時也思考這些變動對違約機率(probability of default)的可能影響。
資料集 cr_loan_clean 已載入工作環境,連同訓練集 X1_train、X2_train 和 y_train 一併提供。
本練習屬於課程
以 Python 進行信用風險建模
練習說明
- 檢查兩個
X訓練集各自的前五列。 - 使用
X1訓練集訓練一個名為clf_logistic1的邏輯斯回歸模型。 - 使用
X2訓練集訓練一個名為clf_logistic2的邏輯斯回歸模型。 - 印出兩個邏輯斯回歸模型的係數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Print the first five rows of each training set
print(____.____())
print(____.____())
# Create and train a model on the first training data
____ = ____(solver='lbfgs').____(____, np.ravel(y_train))
# Create and train a model on the second training data
____ = ____(solver='lbfgs').____(____, np.ravel(y_train))
# Print the coefficients of each model
print(____.____)
print(____.____)