By statement
from keras.utils import to_categorical
Errors are reported when importing category, as follows:
importerror: cannot import name ‘to_ categorical’ from ‘keras.utils’
Change the import code as follows:
from tensorflow.keras.utils import to_categorical