首页 > 解决方案 > 如何在 python jupyter notebook 中将标签从整数转换为向量?

问题描述

我正在尝试应用正确的代码,但总是给我一个错误。这里是代码

trainY =keras.utils.to_categorical(trainY, num_classes=2, dtype='float32')
testY = keras.utils.to_categorical(testY, num_classes=2, dtype='float32')

它会产生一个错误,即

TypeError                                 Traceback (most recent call last)
<ipython-input-23-dea4d664a742> in <module>
      1 # convert the labels from integers to vectors
----> 2 trainY =keras.utils.to_categorical(trainY ,num_classes=2, dtype='float32')
      3 testY = keras.utils.to_categorical(testY, num_classes=2, dtype='float32')

~\Anaconda3\lib\site-packages\keras\utils\np_utils.py in to_categorical(y, num_classes, dtype)
     41     """
     42 
---> 43     y = np.array(y, dtype='int')
     44     input_shape = y.shape
     45     if input_shape and input_shape[-1] == 1 and len(input_shape) > 1:

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

帮助我。谢谢。

标签: pythonmachine-learningkerasdeep-learningjupyter-notebook

解决方案


推荐阅读