Repository navigation
Expand file tree
/
Copy pathknock79.py
More file actions
50 lines (44 loc) · 1.37 KB
/
Copy pathknock79.py
File metadata and controls
50 lines (44 loc) · 1.37 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
from knock78 import train_test_split, score
from sklearn.linear_model import LogisticRegression
try:
from tqdm import tqdm
except:
def tqdm(iter):
return iter
import matplotlib.pyplot as plt
if __name__ == "__main__":
thresholds = []
accuracies = []
precisions = []
recalls = []
f1s = []
for _threshold in tqdm(range(101)):
threshold = _threshold / 100
accuracy = 0
precision = 0
recall = 0
f1 = 0
for k in range(5):
train_x, train_y, test_x, test_y = train_test_split(k)
model = LogisticRegression(solver="liblinear")
_accuracy, _precision, _recall, _f1 = score(
model, train_x, train_y, test_x, test_y, threshold=threshold)
accuracy += _accuracy
precision += _precision
recall += _recall
f1 += _f1
accuracy = accuracy / 5
precision = precision / 5
recall = recall / 5
f1 = f1 / 5
thresholds.append(threshold)
accuracies.append(accuracy)
precisions.append(precision)
recalls.append(recall)
f1s.append(f1)
plt.plot(thresholds, accuracies, label="accuracy")
plt.plot(thresholds, precisions, label="precision")
plt.plot(thresholds, recalls, label="recall")
plt.plot(thresholds, f1s, label="f1")
plt.legend()
plt.show()