LR模型使用sigmoid激活函数和log_loss损失函数后auc为0.5
Created by: a6802739
模型定义如下:
def model():
sparse_input_ids = fluid.layers.data(name='sparse_id', shape=[1], lod_level=1, dtype='int64')
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
datas = [sparse_input_ids, label]
file_list = get_file_list(g_data_path)
info("file_list: " + str(file_list))
py_reader = fluid.contrib.ctr_reader.ctr_reader(
feed_dict=datas, file_type='plain', file_format=g_file_format,
file_list=file_list, dense_slot_index=[], sparse_slot_index=[],
capacity=64, thread_num=g_rd_thd_num, batch_size=g_batch_size, slots=['1'], name='ctr_reader')
sparse_fm_param_attr = fluid.param_attr.ParamAttr(name="SparseFeatFactors")
emb = fluid.layers.embedding(
input=sparse_input_ids, dtype='float32', size=[g_dict_size, 1],
param_attr=sparse_fm_param_attr, is_sparse=True,
is_distributed=True)
pooled = fluid.layers.sequence_pool(input=emb, pool_type='sum')
y_predict = fluid.layers.fc(input=pooled, size=1, act='sigmoid')
y_predict = fluid.layers.Print(y_predict, message = "The content of input layer:")
loss = fluid.layers.log_loss(input=y_predict, label=fluid.layers.cast(label,dtype='float32'))
avg_cost = fluid.layers.mean(x=loss)
inputs = fluid.layers.concat(input=[1-y_predict, y_predict], axis=1)
auc_out, auc_batch_out, auc_status = fluid.layers.auc(input=inputs, label=label)
return datas, avg_cost, y_predict, py_reader, auc_out, auc_batch_out
打印y_predict的结果,得到如下值:
Tensor[fc_0.tmp_2]
shape: [128,1,]
dtype: f
data: 0.499988,0.500018,0.500054,0.49998,0.499933,0.49992,0.500091,0.500105,0.499854,0.499878,0.500095,0.499919,0.50012,0.499804,0.4999
59,0.500116,0.499944,0.499747,0.499922,0.500026,0.499965,0.499957,0.499941,0.500055,0.499998,0.49992,0.500112,0.499835,0.50001,0.500026,0.50002
2,0.500015,0.4999,0.499945,0.499906,0.499816,0.500093,0.499933,0.500219,0.499895,0.499872,0.500102,0.500136,0.499985,0.499896,0.499804,0.500102
,0.500218,0.500153,0.500094,0.499986,0.499883,0.499944,0.499953,0.499819,0.499831,0.499863,0.499859,0.499921,0.499824,0.499949,0.500024,0.50003
7,0.499871,0.500081,0.499835,0.499826,0.499896,0.500004,0.499883,0.500029,0.499904,0.499981,0.500037,0.500003,0.499993,0.499929,0.500087,0.4998
89,0.499906,0.500059,0.499943,0.499998,0.499847,0.499938,0.500155,0.499869,0.499874,0.500041,0.500027,0.500053,0.49984,0.500123,0.499881,0.4998
62,0.500049,0.500006,0.499915,0.500023,0.500057,0.500149,0.500047,0.499997,0.500016,0.49999,0.499994,0.49999,0.500035,0.500025,0.499916,0.49988
,0.499985,0.499921,0.500013,0.499972,0.499933,0.499756,0.500088,0.500149,0.499904,0.499911,0.499887,0.500022,0.500011,0.500017,0.499852,0.50001
7,0.499862,
1562584262 The content of input layer: The place is:CPUPlace
Tensor[fc_0.tmp_2]
shape: [128,1,]
dtype: f
data: 2.72673e-11,4.15131e-14,4.44654e-10,2.53193e-12,4.06194e-14,1.92132e-14,3.02166e-12,2.43138e-13,3.78204e-12,8.02316e-13,2.10133e-
12,4.66164e-13,2.31308e-13,7.15251e-13,1.13968e-13,5.95105e-14,6.90227e-14,7.97088e-14,5.22807e-13,3.69887e-12,8.32232e-13,5.42321e-11,4.53506e
-14,1.8475e-13,2.623e-13,3.89936e-11,4.17723e-10,2.20542e-13,6.53986e-13,6.6298e-14,1.55495e-11,3.29793e-12,8.09207e-13,1.60763e-12,1.45588e-09
,1.0058e-12,3.3279e-11,3.20854e-14,1.18283e-11,2.42427e-13,1.83516e-13,3.96373e-11,1.67322e-12,1.10889e-11,1.85451e-12,2.07841e-13,2.08982e-13,
9.13329e-15,2.03634e-12,3.24285e-10,2.65777e-12,6.5528e-12,9.01445e-13,9.30129e-13,7.48217e-13,8.12523e-12,1.73318e-11,2.12259e-13,1.90726e-13,
5.12034e-13,9.78469e-12,2.42384e-11,3.75191e-13,2.49626e-10,3.45848e-12,9.77365e-11,3.20464e-13,1.94684e-10,8.48704e-14,6.67506e-13,2.09613e-13
,4.23692e-11,4.14215e-12,2.83474e-12,2.17728e-11,3.12621e-14,1.37799e-13,1.74038e-14,5.32869e-11,4.33357e-11,1.49081e-11,1.69397e-11,4.22774e-1
2,3.66975e-12,8.81322e-14,8.48396e-13,1.58442e-11,7.14606e-13,2.17497e-13,3.41917e-11,9.24527e-13,4.59532e-12,3.1305e-10,1.19112e-13,1.04877e-1
0,1.28536e-12,9.30809e-12,1.59216e-13,5.9382e-13,1.75886e-11,1.64854e-13,1.31806e-12,1.78528e-12,5.96261e-13,2.92904e-13,3.22718e-14,4.86109e-1
4,1.87008e-13,8.83608e-14,9.37896e-13,1.03032e-12,8.33721e-14,1.89412e-13,1.191e-13,1.67986e-13,1.08638e-14,5.77859e-14,1.77988e-11,1.3679e-12,
3.68672e-12,2.7899e-14,3.72097e-11,1.18776e-13,1.27351e-11,1.42638e-11,4.71528e-11,2.46509e-14,9.05875e-13,
1562584262 The content of input layer: The place is:CPUPlace
auc的结果基本在0.5左右:
2019-07-08 11:11:04,139-INFO: Epoch: 0, Batch: 4, loss: 0.647509157658, auc: 0.499798732908, batch_auc: 0.5, reader queue:64, sample/second: 8259.45083753