使用tensorflow的神经网络召回率超过100

我正在尝试获取创建模型的所有指标:

def build_rnn_gru_model(tokenizer):    model = tf.keras.Sequential([        tf.keras.layers.Embedding(len(tokenizer.word_index) + 1, 64,input_length=863),        tf.keras.layers.GRU(64, activation='relu', return_sequences=True),        tf.keras.layers.Dense(1, activation='sigmoid')    ])    model.summary()    model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy',f1,precision, recall])    return model

我还使用了在如何获取keras模型的准确率、F1、精确度和召回率?中高度赞同的答案中建议的指标定义,但结果是一样的:

def recall(y_true, y_pred):    true_positives = K.sum(K.round(y_pred) * y_true)    possible_positives = K.sum(y_true)    return true_positives / (possible_positives + K.epsilon())def precision(y_true, y_pred):    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)))    precision = true_positives / (predicted_positives + K.epsilon())    return precisiondef f1(y_true, y_pred):    precision_ = precision(y_true, y_pred)    recall_ = recall(y_true, y_pred)    return 2*((precision_*recall_)/(precision_+recall_+K.epsilon()))

在使用LSTM或没有循环层的模型评估时,一切看起来都正常,但使用GRU时,召回值异常高:

 199/1180 [====>.........................] - ETA: 4:45 - loss: 0.3988 - accuracy: 0.8230 - f1: 1.6155 - precision: 0.8195 - recall: 468.6583

谁能给我一些提示,哪里出了问题?


回答:

对于TF 2,我建议你使用预定义的指标,在你的情况下使用tf.keras.metrics.Recall

model.compile(loss='binary_crossentropy', optimizer='adam', metrics=[tf.keras.metrics.Recall(), ...])

我建议在你的GRU层中设置return_sequences=False,因为我认为你正在进行二分类任务

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注