【发布时间】:2017-11-16 21:37:08
【问题描述】:
我想计算以基尼系数作为优化函数的简单神经网络模型。这是我的 gini 函数:
def gini(actual, pred):
nT = K.shape(actual)[-1]
n = K.cast(nT, dtype='int32')
inds = K.reverse(tf.nn.top_k(pred, n)[1], axes=[0])
a_s = K.gather(actual, inds)
a_c = K.cumsum(a_s)
n = K.cast(nT, dtype=K.floatx())
giniSum = K.cast(K.sum(a_c) / K.sum(a_s), dtype=K.floatx()) - (n + 1) / 2.0
return giniSum / n
def gini_normalized(a, p):
return gini(a, p) / gini(a, a)
这就是我编译模型的方式:
model = Sequential()
model.add(Dense(32, input_shape=(60,)))
model.add(Activation('relu'))
model.add(Dense(2, activation='softmax'))
sgd = optimizers.SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss=gini_normalized, optimizer=sgd)
return model
我总是收到这个错误“ValueError: None values not supported.”,谁能告诉我我的错误是什么?
【问题讨论】:
标签: tensorflow neural-network keras gini