AUC作为喀拉拉邦的指标

时间:2019-07-13 11:43:46

标签: python tensorflow neural-network lstm

我尝试使用auc作为供体选择者数据的lstm中的指标。 模型是多输入单输出。但是我遇到了错误。问题出在哪里?

 import tensorflow as tf
    import keras.backend as K
    import numpy as np
    from sklearn.metrics import roc_auc_score
    from keras.callbacks import Callback
    from  tensorflow.keras.metrics import AUC
    def auc(y_true, y_pred):
    auc = tf.metrics.auc(y_true, y_pred)[1]
    K.get_session().run(tf.local_variables_initializer())
    return auc
    model.compile(optimizer='rmsprop', 
    loss='sparse_categorical_crossentropy',
              loss_weights=[1.], metrics=[auc])
    model.fit([padded_docs_tr,state_tr,grade_category_tr,subject_category_tr, 
          subject_subcategory_tr,prefix_tr,rem_feat_tr], [labels_tr],

    epochs=10,batch_size=1024,callbacks[TensorBoardColabCallback(tbc)])

错误:

  

InvalidArgumentError:找到2个根本错误。 (0)无效的参数:   ValueError:输入形状错误(1024,2)   最后):文件   “ /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/script_ops.py”,   第207行,在调用中返回func(设备,令牌,参数)文件   “ /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/script_ops.py”,   第109行,在调用中ret = self._func(* args)文件   “ /usr/local/lib/python3.6/dist-packages/sklearn/metrics/ranking.py”,   roc_auc_score中的第355行sample_weight = sample_weight)文件   “ /usr/local/lib/python3.6/dist-packages/sklearn/metrics/base.py”,行   76,在_average_binary_score中返回binary_metric(y_true,y_score,   sample_weight = sample_weight)文件   “ /usr/local/lib/python3.6/dist-packages/sklearn/metrics/ranking.py”,   _binary_roc_auc_score中的第327行,sample_weight = sample_weight)   文件   “ /usr/local/lib/python3.6/dist-packages/sklearn/metrics/ranking.py”,   第622行,在roc_curve y_true,y_score,pos_label = pos_label,   sample_weight = sample_weight)文件   “ /usr/local/lib/python3.6/dist-packages/sklearn/metrics/ranking.py”,   第400行,位于_binary_clf_curve y_score = column_or_1d(y_score)   文件   “ /usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py”,   第760行,在column_or_1d中,引发ValueError(“错误的输入形状   {0}“。format(shape))ValueError:输入形状错误(1024,2)[[{{node   metrics_6 / auc / EagerPyFunc}}]] [[metrics_6 / auc / Mean / _505]](1)无效   参数:ValueError:输入形状错误(1024,2)   最后调用):文件   “ /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/script_ops.py”,   第207行,在调用中返回func(设备,令牌,参数)文件   “ /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/script_ops.py”,   第109行,在调用中ret = self._func(* args)文件   “ /usr/local/lib/python3.6/dist-packages/sklearn/metrics/ranking.py”,   roc_auc_score中的第355行sample_weight = sample_weight)文件   “ /usr/local/lib/python3.6/dist-packages/sklearn/metrics/base.py”,行   76,在_average_binary_score中返回binary_metric(y_true,y_score,   sample_weight = sample_weight)文件   “ /usr/local/lib/python3.6/dist-packages/sklearn/metrics/ranking.py”,   _binary_roc_auc_score中的第327行,sample_weight = sample_weight)   文件   “ /usr/local/lib/python3.6/dist-packages/sklearn/metrics/ranking.py”,   第622行,在roc_curve y_true,y_score,pos_label = pos_label,   sample_weight = sample_weight)文件   “ /usr/local/lib/python3.6/dist-packages/sklearn/metrics/ranking.py”,   第400行,位于_binary_clf_curve y_score = column_or_1d(y_score)   文件   “ /usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py”,   第760行,在column_or_1d中,引发ValueError(“错误的输入形状   {0}“。format(shape))ValueError:输入形状错误(1024,2)[[{{node   metrics_6 / auc / EagerPyFunc}}]] 0次成功操作。0个衍生错误

0 个答案:

没有答案