python - 值错误 : The model is not configured to compute accuracy

标签 python tensorflow keras scikit-learn

当使用我从一些教程中获得的这段代码时,我收到错误消息,指出模型未配置为计算准确度,我应该通过准确度,奇怪的是我已经通过了 metrics = ['accuracy']

我搜索了很多,我看到的所有代码都可以正常工作,但我的除外。

评估 ANN

from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.model_selection import cross_val_score
from tensorflow.python.keras.models import Sequential #Used to initialize the NN
from tensorflow.python.keras.layers import Dense #Used to create the layers in the ANN

def build_classifier():
    classifier = Sequential()
    classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu',input_dim = 11))
    classifier.add(Dense(units= 6, kernel_initializer = 'uniform', activation = 'relu'))
    classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))
    classifier.compile(optimizer='adam', loss='binary_crossentropy', metrics= ['accuracy'])
    return classifier
# Needs to be revised from evaluting video in the course if needed
classifier = KerasClassifier(build_fn = build_classifier, batch_size = 10, nb_epoch = 100)
accuracies = cross_val_score(estimator = classifier, X = X_train, y = y_train, cv = 10, n_jobs = -1)

我希望输出是精度向量,但我得到了:

ValueError: The model is not configured to compute accuracy. You should pass metrics=["accuracy"] to the model.compile() method.

最佳答案

将 metrics=['accuracy'] 的参数更改为 metrics=['acc'] 对我有用。

问候, 约瑟夫

关于python - 值错误 : The model is not configured to compute accuracy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56995802/

相关文章:

c++ - 使用 Tensorflow/Bazel 从 C++ 调用 Python 时出现链接错误

python - 使用不同 tf 设备的 keras 训练模型

machine-learning - 连接无输出的 Keras 模型

python - 我对 numpy searchsorted 做错了什么?

python - 如何使用 python 中的枚举将值放入列表中?

python - "Exception ignored in"是什么类型的消息?

python - 如果我需要跳过列表之间的某些字符,如何转换列表列表中的列表?

python - tf.session.run 的网络输出与使用 keras.Model.predict 获得的网络输出有很大不同

python - 如何高效更新 Keras 变量切片?

python - 用于传递 y_true 和 y_pred 以外的参数的 Keras 自定义损失函数