Skip to content

Commit 956106f

Browse files
committed
Add better table
1 parent 93aac0e commit 956106f

File tree

3 files changed

+58
-14
lines changed

3 files changed

+58
-14
lines changed

get_max_scores.py

+35-7
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,51 @@ def getMaxScoreMethod(label, arr):
1414
max_score_method = experiment
1515
return max_score_method
1616

17+
def removeRandomStateParam(model):
18+
if (model != None):
19+
d=model.get_params()
20+
d['random_state'] = None
21+
model.set_params(**d)
22+
return model
23+
24+
1725
def renderMaxScoreMethod(label, arr):
1826
d = getMaxScoreMethod(label, arr)
1927
html = "<h3>Method for: maximum of " + label + "</h3>"
2028
html += "<p><ul>"
2129
for key, value in d.items():
2230
if (key == 'oversampler' or key == 'classifier'):
2331
value = removeRandomStateParam(value)
24-
html += "<li>" + key + " "+str(value)+"</li>"
32+
if (key == 'cm'):
33+
html += "<li>" + str(key) + ":<br>" + showCM(value) +"</li>"
34+
else:
35+
html += "<li>" + key + " " + str(value) + "</li>"
2536
html+= "</ul></p>"
2637
return html
2738

28-
def removeRandomStateParam(model):
29-
if (model != None):
30-
d=model.get_params()
31-
d['random_state'] = None
32-
model.set_params(**d)
33-
return model
39+
def showCM(cm):
40+
cm /= cm.sum()
41+
cm = cm*100
42+
cm = cm.round(2)
43+
html = "<table style=''>\
44+
<tr>\
45+
<th></th>\
46+
<th style='font-weight: bold;'>Negative predicted</th>\
47+
<th style='font-weight: bold;'>True predicted</th>\
48+
</tr>\
49+
<tr>\
50+
<td style='font-weight: bold;'>Negative known</td>\
51+
<td>TN: {}%</td>\
52+
<td>FP: {}%</td>\
53+
</tr>\
54+
<tr>\
55+
<td style='font-weight: bold;'>True known</td>\
56+
<td>FN: {}%</td>\
57+
<td>TP: {}%</td>\
58+
</tr>\
59+
</table>".format(cm[0,0], cm[1,0], cm[0,1], cm[1,1])
60+
return html
61+
3462

3563
def renderHTML(name,arr,dataset):
3664
if (len(arr) == 0):

main.py

+23-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from imblearn.over_sampling import RandomOverSampler, SMOTE, BorderlineSMOTE, SMOTEN
1919
from imblearn.under_sampling import RandomUnderSampler
2020
from sklearn.ensemble import RandomForestClassifier
21+
from sklearn.svm import LinearSVC
22+
from sklearn.svm import SVC
2123

2224
input_path = "datasets/"
2325
output_path = "results/"
@@ -188,13 +190,33 @@ def main():
188190
(
189191
'GBM',GradientBoostingClassifier(),
190192
[{
191-
'n_estimators': [50, 100, 200]
193+
'n_estimators': [50, 100, 200],
194+
'loss': ['deviance', 'exponential'],
195+
'max_features': ['sqrt', 'log2']
192196
}]
193197
),(
194198
'KNN',KNeighborsClassifier(),
195199
[{
196200
'n_neighbors': [3,5,8]
197201
}]
202+
),(
203+
'SVC',SVC(),
204+
[{
205+
'kernel': ['linear', 'poly', 'sigmoid']
206+
}]
207+
),(
208+
'LinearSVC-l1',LinearSVC(),
209+
[{
210+
'penalty': ['l1'],
211+
'loss': ['squared_hinge'],
212+
'dual': [False]
213+
}]
214+
),(
215+
'LinearSVC-l2',LinearSVC(),
216+
[{
217+
'penalty': ['l2'],
218+
'loss': ['hinge', 'squared_hinge']
219+
}]
198220
),(
199221
'RandomForestClassifier', RandomForestClassifier(),
200222
[{
@@ -227,12 +249,6 @@ def main():
227249
[{
228250
'k_neighbors': [3,5,20]
229251
}]
230-
),
231-
(
232-
'B2-SMOTE', BorderlineSMOTE(kind='borderline-2'),
233-
[{
234-
'k_neighbors': [3,5,20]
235-
}]
236252
)
237253
]
238254

File renamed without changes.

0 commit comments

Comments
 (0)