Error “TypeError: type numpy.ndarray doesn't define __round__ method”

前端 未结 5 1227
小蘑菇
小蘑菇 2020-12-31 04:14
import numpy

......

# Prediction
predictions = model.predict(X_test)
# round predictions
rounded = [round(x) for x in predictions]
print(rounded)

\"predictions\"          


        
5条回答
  •  不知归路
    2020-12-31 05:03

    You're using a function that uses Numpy to store values. Instead of being a regular Python list, it is actually a Numpy array. This is generally because with machine learning, Numpy does a much better job at storing massive amounts of data compared to an ordinary list in Python. You can refer to the following documentation to convert to a regular list which you can then preform a comprehension:

    https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.tolist.html

    Edit:

    What happens if you try:

    for x in predictions:
       for y in x.:
        print(y, end=' ')
    

提交回复
热议问题