I have a code was shown below:
history['test_acc'].append(results.history['val_dense_5_accuracy'][0])
then I want to print like below:
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))`
but in this this line:
'Test_acc:', history['test_acc'][-1].round(4)
i have this error: 'float' object has no attribute 'round' what's the problem?
Round() Round() is a built-in function available with python. It will return you a float number that will be rounded to the decimal places which are given as input. If the decimal places to be rounded are not specified, it is considered as 0, and it will round to the nearest integer.
The Python "TypeError: 'float' object is not iterable" occurs when we try to iterate over a float or pass a float to a built-in function like, list() or tuple() . To solve the error, use the range() built-in function to iterate over a range, e.g. for i in range(int(3.0)): . Here is an example of how the error occurs.
The error “TypeError: 'float' object is not subscriptable” occurs when you try to access a floating-point number like a list. To solve this error, ensure you only use indexing or slicing syntax on a subscriptable object, like a list or a string.
The Python "AttributeError: 'float' object has no attribute" occurs when we try to access an attribute that doesn't exist on a floating-point number, e.g. 5.4. To solve the error, make sure the value is of the expected type before accessing the attribute. Here is an example of how the error occurs.
If we call the get() method on the float data type, Python will raise an AttributeError: ‘float’ object has no attribute ‘get’. The error can also happen if you have a method which returns an float instead of a dictionary. Let us take a simple example to reproduce this error.
You can round a float number in several ways using python. In this post we will cover: We can round float number in python by using round () which is a built-in function. It will round number x rounded to y decimal points. You can use function format if you want to round floats.
@xieyj17 round () by itself is a python op which will be slower on numpy arrays. @xieyj17 @seedergy where exactly in the code are you seeing this error?
The problem is that round
is a built-in top level function, not a method on float
s. Change:
history['test_acc'][-1].round(4)
to:
round(history['test_acc'][-1], 4)
with a similar change to the test_loss
expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With