-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogisticRegression_ExperimentData.py
38 lines (30 loc) · 1.46 KB
/
LogisticRegression_ExperimentData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
# open the file
input_file = pd.read_csv('DSL-StrongPasswordData-modified.csv')
# save the data as a np array
data = input_file.to_numpy()
# slice the data for easier reading
X = data[:, :-2]
y = data[:, -1]
# use an 80/20 split for training and testing data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
# create and train the model with no cross validation and l2 penalty
classifier_l2_penalty = LogisticRegression(penalty='l2', max_iter=1000)
classifier_l2_penalty.fit(X_train, y_train)
# create and train the model with no cross validation and no penalty
classifier_no_penalty = LogisticRegression(penalty='no_penalty', max_iter=1000)
classifier_no_penalty.fit(X_train, y_train)
# save the train and test scores
score_train_l2_penalty = classifier_l2_penalty.score(X_train, y_train)
score_test_l2_penalty = classifier_l2_penalty.score(X_test, y_test)
score_train_no_penalty = classifier_no_penalty.score(X_train, y_train)
score_test_no_penalty = classifier_no_penalty.score(X_test, y_test)
# print the scores
print('L2 Penalty Training score:', score_train_l2_penalty)
print('L2 Penalty Testing score:', score_test_l2_penalty)
print('No Penalty Training score:', score_train_no_penalty)
print('No Penalty Testing score:', score_test_no_penalty)