add visualization for training curves, pr, roc

This commit is contained in:
2017-07-14 14:58:17 +02:00
parent d0418b9efa
commit b35f23e518
7 changed files with 299 additions and 99 deletions

View File

@@ -1,3 +1,6 @@
import keras.backend as K
import dataset
from . import pauls_networks
from . import renes_networks
@@ -6,7 +9,7 @@ def get_models_by_params(params: dict):
# decomposing param section
# mainly embedding model
network_type = params.get("type")
vocab_size = params.get("vocab_size")
vocab_size = len(dataset.get_character_dict()) + 1
embedding_size = params.get("embedding_size")
input_length = params.get("input_length")
filter_embedding = params.get("filter_embedding")
@@ -30,3 +33,51 @@ def get_models_by_params(params: dict):
filter_main, kernel_main, dense_dim, embedding_model)
return embedding_model, predict_model
def get_metrics():
return dict([
("precision", precision),
("recall", recall),
("f1_score", f1_score),
])
def get_metric_functions():
return [precision, recall, f1_score]
def precision(y_true, y_pred):
# Count positive samples.
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
return true_positives / (predicted_positives + K.epsilon())
def recall(y_true, y_pred):
# Count positive samples.
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
return true_positives / (possible_positives + K.epsilon())
def f1_score(y_true, y_pred):
return f_score(1)(y_true, y_pred)
def f05_score(y_true, y_pred):
return f_score(0.5)(y_true, y_pred)
def f_score(beta):
def _f(y_true, y_pred):
p = precision(y_true, y_pred)
r = recall(y_true, y_pred)
bb = beta ** 2
fbeta_score = (1 + bb) * (p * r) / (bb * p + r + K.epsilon())
return fbeta_score
return _f