Python 使用条件将我的模型预测数组转换为分类数组
我已经建立了一个MLP神经网络->训练->保存->加载->现在我正在测试加载的模型 我使用了Python 使用条件将我的模型预测数组转换为分类数组,python,arrays,numpy,keras,pytorch,Python,Arrays,Numpy,Keras,Pytorch,我已经建立了一个MLP神经网络->训练->保存->加载->现在我正在测试加载的模型 我使用了y_pred=loaded_model(Variable(featuresTest))来使用pytorch进行预测,然后将我的张量转换为数组y_pred_arr,下面是我的结果: 数组([-1.1663326,0.369073], [-1.4255922 , 0.23584184], [-2.045612 , 1.4165274 ], ..., [ 4.327711 , -4.1331964 ],
y_pred=loaded_model(Variable(featuresTest))
来使用pytorch进行预测,然后将我的张量转换为数组y_pred_arr
,下面是我的结果:
数组([-1.1663326,0.369073],
[-1.4255922 , 0.23584184],
[-2.045612 , 1.4165274 ],
...,
[ 4.327711 , -4.1331964 ],
[-1.255816 , 0.65834284],
[6.642277,-7.4430957]],数据类型=float32)
我要比较的真标签数组y\u test
是分类的
array([[0., 1.],
[0., 1.],
[0., 1.],
...,
[1., 0.],
[0., 1.],
[1., 0.]], dtype=float32)
现在我尝试使用sklearn.metrics
->分类报告,但由于我预测的数组显然是连续的,我尝试将其转换为一个分类,该分类使用一个条件将每个数组中的最高正数转换为1
,例如:
我在预测数组中的第一个集合是[-1.4255922,0.23584184],
试试这个
from keras.utils.np_utils import to_categorical
labels123 = to_categorical(np.argmax(y_pred_arr, 1), dtype = "int64")
哇,谢谢你这么多的工作!!!!!!!!!!!!请点击我答案旁边的复选标记,接受我的答案。如果你觉得它有用的话,你也可以投票给它。
IndexError: index -75 is out of bounds for axis 1 with size 74
from keras.utils.np_utils import to_categorical
labels123 = to_categorical(np.argmax(y_pred_arr, 1), dtype = "int64")