CTR场景数据分析建模 问题汇总3 - 引入DNN

keras 中没有auc metric的问题

查了keras的官方说明文档,metric中并没有auc选值可选。需要自己自定义auc计算方法。
https://blog.csdn.net/xwd18280820053/article/details/78740379
这篇文章我使用了其方法一,亲测可行。
代码如下:
需要在代码前端插入相关函数

from sklearn.metrics import roc_auc_score
import tensorflow as tf
from keras import backend as K
# AUC for a binary classifier
def auc(y_true, y_pred):
    ptas = tf.stack([binary_PTA(y_true,y_pred,k) for k in np.linspace(0, 1, 1000)],axis=0)
    pfas = tf.stack([binary_PFA(y_true,y_pred,k) for k in np.linspace(0, 1, 1000)],axis=0)
    pfas = tf.concat([tf.ones((1,)) ,pfas],axis=0)
    binSizes = -(pfas[1:]-pfas[:-1])
    s = ptas*binSizes
    return K.sum(s, axis=0)
#-----------------------------------------------------------------------------------------------------------------------------------------------------
# PFA, prob false alert for binary classifier
def binary_PFA(y_true, y_pred, threshold=K.variable(value=0.5)):
    y_pred = K.cast(y_pred >= threshold, 'float32')
    # N = total number of negative labels
    N = K.sum(1 - y_true)
    # FP = total number of false alerts, alerts from the negative class labels
    FP = K.sum(y_pred - y_pred * y_true)
    return FP/N
#-----------------------------------------------------------------------------------------------------------------------------------------------------
# P_TA prob true alerts for binary classifier
def binary_PTA(y_true, y_pred, threshold=K.variable(value=0.5)):
    y_pred = K.cast(y_pred >= threshold, 'float32')
    # P = total number of positive labels
    P = K.sum(y_true)
    # TP = total number of correct alerts, alerts from the positive class labels
    TP = K.sum(y_pred * y_true)
    return TP/P

在keras的fit函数中加以调用 调用auc函数

model.compile(optimizer=optimizer, loss='mse', metrics=[auc])

大功告成

Key Error: None of [Int64Index…] dtype='int64] are in the columns

本错误发生的原因在国内论坛上没有看到解决办法…看StackOverflow上有相关解答。
https://stackoverflow.com/questions/55875744/receiving-keyerror-none-of-int64index-dtype-int64-length-1323-are
错误的问题就在于:keras默认输入到input层的数据是np格式的,而我这里因为使用pandas对元数据进行预处理及特征工程,所以输入网络的都是pandas的dataframe格式,并不是np格式。
解决办法:
在划分测试验证集的功能实现中,需要把dataframe格式内的数值转换成np格式。
直接在dataframe格式变量后加.values即可
代码如下所示,最后将测试验证集变量加.values

target = ['1']

valid_data_x = valid_data[train_feature].reset_index(drop=True)
valid_data_y = valid_data['1'].reset_index(drop=True)
train_data_x = train_data[train_feature].reset_index(drop=True)
train_data_y = train_data['1'].reset_index(drop=True)

train_data_x_without_valid = train_data_x.drop(valid_data.index).values #转np
train_data_y_without_valid = train_data_y.drop(valid_data.index).values #转np

valid_data_x=valid_data_x.values #转np
valid_data_y=valid_data_y.values #转np
train_data_x =train_data_x.values #转np
train_data_y = train_data_y.values #转np

使用 keras EarlyStopping功能时出现 TypeError: unsupported operand type(s) for -: ‘NoneType’ and ‘int’

https://stackoverflow.com/questions/42472416/how-do-i-prevent-the-typeerror-unsupported-operand-types-for-nonetype-an

问题代码

early_stopping = EarlyStopping(monitor='val_mean_absolute_error', mode='min', patience=4, verbose=1)

monitor有点问题,但是目前还不太清楚发生了什么问题,将其更改为’val_loss’后恢复正常

更改如下

early_stopping = EarlyStopping(monitor='val_loss', patience=4,verbose=1)

其他 下一步信号方面方向

检测:
ad9361
循环谱密度 带宽 速率 用于ddc
高阶累积量
mimo

功率谱 平方谱 高阶谱
单音干扰 多因
信道占用情况

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值