Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 通过预处理得到模型的精度_Python_Keras - Fatal编程技术网

Python 通过预处理得到模型的精度

Python 通过预处理得到模型的精度,python,keras,Python,Keras,我想得到我的模型预测x\u测试标签的准确性 from __future__ import print_function from keras.models import Sequential from keras.layers import Dense import keras import numpy as np model = Sequential() model.add(Dense(2000, input_dim=3072, activ

我想得到我的模型预测
x\u测试标签的准确性

   from __future__ import print_function
    from keras.models import Sequential
    from keras.layers import Dense
    import keras
    import numpy as np
    model = Sequential()
    model.add(Dense(2000, input_dim=3072, activation='relu'))
    model.add(Dense(500, activation='relu'))
    model.add(Dense(66, activation='softmax'))
    model.fit(x_train,y_train, epochs=100, batch_size=128)
    scores = model.evaluate(x_train, y_train)
    print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
现在我想知道预测的准确性

predictions = model.predict(x_test)
我试过:

  print("\n%s: %.2f%%" % (model.metrics_names[1], predictions*100))
我得到了以下错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-262-edbcf292f31c> in <module>()
----> 1 print("\n%s: %.2f%%" % (model.metrics_names[1], predictions*100))

TypeError: float argument required, not numpy.ndarray
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
在()
---->1次打印(“\n%s:%.2f%%”%”%(model.metrics\u名称[1],预测*100))
TypeError:需要浮点参数,而不是numpy.ndarray

model.predict
生成一个
numpy.array
,它与
float
完全不同。您可以尝试使用
print(predictions)
打印,但在这种情况下,使用带
float
的格式化字符串绝对不起作用。尝试:

print("\n%s:" % (model.metrics_names[1]))
print(100 * predictions)

或者如果在
x\u测试中只有一个案例

print("\n%s: %.2f%%" % (model.metrics_names[1], predictions[0]*100))
预测是有规律的(2000,50)。我想得到每行的最大概率。我尝试了predictions.max(),但它返回整个2d数组的最大值,但是我正在寻找一个1D向量2000,其中每个值表示行中的最大值try
max(axis=1)
print("\n%s: %.2f%%" % (model.metrics_names[1], predictions[0]*100))