首页 > 解决方案 > 'float' 对象没有属性 'round'

问题描述

我有一个代码如下所示:

history['test_acc'].append(results.history['val_dense_5_accuracy'][0]) 

然后我想打印如下:

 print('Epoch: '+str(epoch)+'/'+str(epochs-1), 'Learning rate:', 
      'Test_acc:', history['test_acc'][-1].round(4),
      'Test_loss:', history['test_loss'][-1].round(4))`

但在这一行:

'Test_acc:', history['test_acc'][-1].round(4)

我有这个错误:'float'对象没有属性'round'有什么问题?

标签: pythonkeras

解决方案


问题是这round是一个内置的顶级函数,而不是floats 上的方法。改变:

history['test_acc'][-1].round(4)

至:

round(history['test_acc'][-1], 4) 

test_loss表达式类似的变化。


推荐阅读