gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 17:58:20 24 4
gpt4 key购买 nike

当使用我从一些教程中获得的这段代码时,我收到错误消息,指出模型未配置为计算准确度,我应该通过准确度,奇怪的是我已经通过了 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com