使用tflearn的二进制输出

时间:2017-07-16 19:52:01

标签: python tensorflow neural-network deep-learning tflearn

我是tflearn / tensorflow的先生。 我正在制作DNN,以正常 (0) Arrhytmia (1)对心跳进行分类。我的数据集是ECG by MIT Arrhytmia Dataset ..

我建立了以下网:

## Build neural network
net = tflearn.input_data(shape=[None, 200])
net = tflearn.fully_connected(net, 400)
net = tflearn.fully_connected(net, 400)
net = tflearn.fully_connected(net, 100)
net = tflearn.fully_connected(net, 50)
net = tflearn.fully_connected(net, 1, activation='linear')
net = tflearn.regression(net, optimizer='adam', learning_rate=0.01,loss='mean_square', name='target')
##
## Define model
model = tflearn.DNN(net)
print('fiting')
model.fit(TrainSet, labelSet, n_epoch=5000, batch_size=len(TrainSet), show_metric=True)

我的输出是:

y pred                   y target
predict:[0.01360663]      [0]
predict:[0.00861748]      [0]
predict:[-0.00685573]     [0]
predict:[-0.20846206]     [1]

我的网络分离良好,正常样本(predict:[0.00861748] [0])的输出与心律失常样本(predict:[-0.20846206] [1])的输出完全不同

那么,我怎样才能使输出只有01这个浮动值? 也许改变我的激活功能?或用我的实际输出做点什么?

这是我的输出:model.predict(TrainingSet)

y predicted             y target
predict:[-0.138634]     [0]
predict:[-0.13436639]     [0]
predict:[-0.12879151]     [0]
predict:[-0.12057236]     [0]
predict:[-0.13836551]     [0]
predict:[-0.08525576]     [0]
predict:[ 1.01741135]     [1]
predict:[-0.11624834]     [0]
predict:[-0.12631142]     [0]
predict:[-0.11693959]     [0]
predict:[-0.10779606]     [0]
predict:[-0.11510199]     [0]
predict:[-0.12450527]     [0]
predict:[-0.12869376]     [0]
predict:[-0.15167347]     [0]
predict:[-0.14081171]     [0]
predict:[-0.14235598]     [0]
predict:[-0.13095573]     [0]
predict:[-0.12757528]     [0]
predict:[-0.14675851]     [0]
predict:[-0.12311366]     [0]
predict:[-0.15386838]     [0]
predict:[-0.17505151]     [0]
predict:[-0.13848163]     [0]
predict:[-0.11671469]     [0]
predict:[-0.13247125]     [0]
predict:[-0.13718334]     [0]
predict:[-0.12702732]     [0]
predict:[-0.12665084]     [0]
predict:[-0.1367469]     [0]
predict:[-0.15925398]     [0]
predict:[-0.13639028]     [0]
predict:[-0.11569472]     [0]
predict:[-0.14167]     [0]
predict:[-0.12262306]     [0]
predict:[-0.10863069]     [0]
predict:[-0.14324963]     [0]
predict:[-0.14792402]     [0]
predict:[-0.14929616]     [0]
predict:[-0.15551159]     [0]
predict:[-0.11816701]     [0]
predict:[-0.11785387]     [0]
predict:[-0.15215725]     [0]
predict:[-0.11279716]     [0]
predict:[-0.1469961]     [0]
predict:[-0.14991215]     [0]
predict:[-0.11661309]     [0]
predict:[-0.09011015]     [0]
predict:[-0.09775476]     [0]
predict:[-0.1065342]     [0]
predict:[-0.11091903]     [0]
predict:[-0.10344772]     [0]
predict:[-0.12412915]     [0]
predict:[-0.13605709]     [0]
predict:[-0.12797417]     [0]
predict:[-0.1076207]     [0]
predict:[-0.12150024]     [0]
predict:[-0.13840012]     [0]
predict:[-0.13084875]     [0]
predict:[-0.11066008]     [0]
predict:[-0.12374203]     [0]
predict:[-0.13341869]     [0]
predict:[-0.12912038]     [0]
predict:[-0.13748281]     [0]
predict:[-0.13966258]     [0]
predict:[-0.13894111]     [0]
predict:[-0.10213074]     [0]
predict:[-0.15602994]     [0]
predict:[-0.12982219]     [0]
predict:[-0.09376201]     [0]
predict:[-0.08830833]     [0]
predict:[-0.12029025]     [0]
predict:[-0.09362413]     [0]
predict:[ 1.09521723]     [1]
predict:[-0.13147078]     [0]
predict:[-0.1182971]     [0]
predict:[-0.12983324]     [0]
predict:[-0.18321729]     [0]
predict:[-0.18334746]     [0]
predict:[-0.2399022]     [0]

1 个答案:

答案 0 :(得分:0)

一种方法是将激活功能更改为“softmax”并将预测四舍五入。你可以这样做;

net = tflearn.fully_connected(net, 1, activation='sigmoid ')

并预测:

pred = model.predict(test_data)     
print([ np.where(r==1)[0][0] for r in np.round(pred)])

这应该有效。