3. Details of Logistic Regression and Feature Exploration
Activity 3.01: Fitting a Logistic Regression Model and Directly Using the Coefficients
Solution:
The first few steps are similar to things we've done in previous activities:
- Create a train/test split (80/20) with
PAY_1
andLIMIT_BAL
as features:from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split( Â Â Â Â df[['PAY_1', 'LIMIT_BAL']].values, Â Â Â Â df['default payment next month'].values, Â Â Â Â test_size=0.2, random_state=24)
- Import
LogisticRegression
, with the default options, but set the solver toÂ'liblinear'
:from sklearn.linear_model import LogisticRegression lr_model = LogisticRegression(solver='liblinear')
- Train on the training data and obtain predicted classes, as well as class probabilities, using the test data:
lr_model.fit(X_train, y_train...