python - 'float' 对象没有属性 'round'

标签 python keras

我有一个代码如下所示:

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 is a built-in top level function ,而不是 float 上的方法。改变:

history['test_acc'][-1].round(4)
至:
round(history['test_acc'][-1], 4) 
test_loss 表达式有类似的变化。

关于python - 'float' 对象没有属性 'round',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65277758/

相关文章:

Python MYSQL 插入问题 : not enough arguments for format string

python-3.x - 如何在keras预处理器中传递数组而不是路径

machine-learning - Keras 中的自定义损失函数用于惩罚漏报

python - 如何防止keras自定义损失函数中的负面预测

python - 如何在基类方法中使用派生类变量

Python 线程/线程实现

python - 使用 gdal/python 重新投影和镶嵌 MODIS level2

machine-learning - keras(或任何其他机器学习框架)如何计算用于反向传播的 lambda 函数层的梯度?

python-3.x - Keras 中的 fit_generator 是否应该在每个纪元后重置生成器?

python - 为什么在我创建新用户时 Django 用户密码没有加密?