@@ -86,31 +86,32 @@ def prepare_data():
86
86
return train_test_split (x , y , test_size = 0.30 , stratify = y , random_state = 1 )
87
87
88
88
89
- def main ():
89
+ def logistic_regression ():
90
90
"""
91
91
- create training and test data sets
92
92
- create a Logistic Regression model
93
93
- train the model
94
94
- generate confusion matrix and f-score for the training set
95
95
- generate confusion matrix and f-score for the test set
96
96
"""
97
+ print ("Prepare data" )
97
98
x_train , x_test , y_train , y_test = prepare_data ()
98
99
99
- # Fit a logistic regression model
100
+ print ( "train model" )
100
101
model = LogisticRegression ()
101
102
model .fit (x_train , y_train )
102
103
103
104
# Set the optimal threshold (refer to the Jupyter Notebook to see how we arrived at 42)
104
105
optimal_threshold = 0.42
105
106
106
- # Create a confusion matrix for the training data
107
+ print ( "model training data and measure results" )
107
108
y_pred_train = model .predict_proba (x_train )
108
109
metrics_score (y_train , y_pred_train [:, 1 ] > optimal_threshold )
109
110
110
- # Create a confusion matrix for the test data
111
+ print ( "model test data and measure results" )
111
112
y_pred_test = model .predict_proba (x_test )
112
113
metrics_score (y_test , y_pred_test [:, 1 ] > optimal_threshold )
113
114
114
115
115
116
if __name__ == "__main__" :
116
- main ()
117
+ logistic_regression ()
0 commit comments