質問編集履歴
1
予測モデルの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -7,3 +7,77 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
わかる方よろしくお願いします。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
予測モデルです。
|
16
|
+
|
17
|
+
```python
|
18
|
+
|
19
|
+
import pandas as pd
|
20
|
+
|
21
|
+
from sklearn.model_selection import train_test_split
|
22
|
+
|
23
|
+
from sklearn.svm import SVC
|
24
|
+
|
25
|
+
from sklearn.metrics import accuracy_score
|
26
|
+
|
27
|
+
from sklearn.metrics import confusion_matrix
|
28
|
+
|
29
|
+
from sklearn.metrics import f1_score
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
# データの読み込み --- (*1)
|
34
|
+
|
35
|
+
analysisresults_data = pd.read_csv("analysis_resultstableFAB.csv",encoding="utf-8")
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
# データをラベルと入力データに分離する --- (*2)
|
40
|
+
|
41
|
+
y = analysisresults_data.loc[:,"analysis_result"]
|
42
|
+
|
43
|
+
x = analysisresults_data.loc[:,["signatures_id","hit_count"]]
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
# 学習用とテスト用に分離する --- (*3)
|
48
|
+
|
49
|
+
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.2, train_size = 0.8, shuffle = True, random_state=0)
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
# 学習する --- (*4)
|
54
|
+
|
55
|
+
clf = SVC()
|
56
|
+
|
57
|
+
clf.fit(x_train, y_train)
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
# 評価する --- (*5)
|
62
|
+
|
63
|
+
y_pred = clf.predict(x_test)
|
64
|
+
|
65
|
+
print("正解率 = " , accuracy_score(y_test, y_pred))
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
tp, fn, fp, tn = confusion_matrix(y_test, y_pred).ravel()
|
70
|
+
|
71
|
+
print("TP,FN,FP,TN = ",tp,fn,fp,tn)
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
FPR = fp/(fp+tn)
|
76
|
+
|
77
|
+
print("偽陽性率 = ",FPR)
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
print("F値 = " , f1_score(y_test, y_pred))
|
82
|
+
|
83
|
+
```
|