我正在尝试计算模型所做的预测的微 F 测量。我使用带有 Keras 和 Tensorflow 的 word2vec 矢量来训练模型。我使用 scikit 库来计算 mirco F 度量。
但该函数会抛出此消息:
ValueError: Classification metrics can't handle a mix of multilabel-indicator and continuous-multioutput targets
另外,我的预测对吗?我训练模型x_train(wordVectors)
and y_train(resultVectors)
并通过验证x_test
and y_test
.
现在我做了一个预测x_test
并想使用评估预测y_test
。到目前为止我做得对吗?
预测数组如下所示:
[[ 1.7533608e-02 5.8055294e+01 2.2185498e-03 ... -1.2394511e-03
1.0454212e+00 -1.6698670e-03]
[ 1.7539740e-02 5.8173992e+01 2.1747553e-03 ... -1.2764656e-03
1.0475068e+00 -1.6941782e-03]
[ 1.7591618e-02 5.8222389e+01 2.2053251e-03 ... -1.2856000e-03
1.0484750e+00 -1.6668942e-03] ...
真实值如下所示:
[[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]...
我已经尝试将两个数组转换为二进制值(使用np.argmax(..., axis=1)
)。然后就没有错误了,我得到的微 F 值约为 0.59……这太高了,所以我认为我犯了一个错误。
我的问题是是否有另一种方法来转换数据?我可以将预测转换为多标签指标值吗?
model = load_model('model.h5')
prediction = model.predict(x_test)
prediction_binary = np.argmax(prediction, axis=1)
y_test_binary = np.argmax(y_test, axis=1)
print(f1_score(y_test_binary, prediction_binary, average='micro'))
我期望输出