如何使用sklearn的keras模型分类报告?

mem*_*mis 2 scikit-learn keras

所以我写了一个网络,其中包括以下多类分类:-y_labels用to_categorical -last层转换使用sigmoid函数和3个神经元作为我的类-model编译使用categorical_crossentropy作为损失函数所以我用过

 model.predict_classes(x_test)
Run Code Online (Sandbox Code Playgroud)

然后我用它作为

   classification_report(y_test,pred)
Run Code Online (Sandbox Code Playgroud)

y_test的格式为to_categorical我收到以下错误:

ValueError: Mix type of y not allowed, got types set(['binary', 'multilabel-indicator'])
Run Code Online (Sandbox Code Playgroud)

我的问题是我怎样才能将其转换回来以便使用它呢?

ind*_*you 5

该错误仅表示该类型y_test并且pred具有不同类型.检查功能type_of_targetmulticlass.py.如此处所示,其中一个y是类的指示符,另一个是类向量.您可以通过打印形状来推断哪一个是什么y_test.shape , pred.shape.

更多,因为你使用model.predict_classes而不是model.predict你的输出model.predict_classes将只是类而不是类向量.

所以要么你需要通过以下方式转换其中一个:

# class --> class vector
from keras.utils import np_utils
x_vec = np_utils.to_categorical(x, nb_classes)

# class vector --> class 
x = x_vec.argmax(axis=-1)
Run Code Online (Sandbox Code Playgroud)