gpt4 book ai didi

tensorflow - 属性错误 : 'Sequential' object has no attribute 'predict_proba'

转载 作者:行者123 更新时间:2023-12-05 01:57:39 25 4
gpt4 key购买 nike

predict_proba 返回神经网络中的误差

我在这个链接上看到了例子 https://machinelearningmastery.com/how-to-make-classification-and-regression-predictions-for-deep-learning-models-in-keras/

https://faroit.com/keras-docs/1.0.0/models/sequential/#the-sequential-model-api

我使用的是 Tensorflow 版本:2.6.0

代码:

#creating the object (Initializing the ANN)
import tensorflow as tf
from tensorflow import keras
LAYERS = [
tf.keras.layers.Dense(50, activation="relu", input_shape=X_train.shape[1:]),
tf.keras.layers.LeakyReLU(),
tf.keras.layers.Dense(25, activation="relu"),
tf.keras.layers.Dense(10, activation="relu"),
tf.keras.layers.Dense(5, activation="relu"),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(1, activation='sigmoid')
]

LOSS = "binary_crossentropy"
OPTIMIZER = tf.keras.optimizers.Adam(learning_rate=1e-3)

model_cEXT = tf.keras.models.Sequential(LAYERS)
model_cEXT.compile(loss=LOSS , optimizer=OPTIMIZER, metrics=['accuracy'])

EPOCHS = 100

checkpoint_cb = tf.keras.callbacks.ModelCheckpoint("model_cEXT.h5", save_best_only=True)
early_stopping_cb = tf.keras.callbacks.EarlyStopping(patience=10, restore_best_weights=True)
tensorboard_cb = tf.keras.callbacks.TensorBoard(log_dir="logs")
CALLBACKS = [checkpoint_cb, early_stopping_cb, tensorboard_cb]

model_cEXT.fit(X_train, y_train['cEXT'], epochs = EPOCHS, validation_data=(X_test, y_test['cEXT']), callbacks = CALLBACKS)

model_cEXT.predict_proba(X_test)

错误:

---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-72-8f06353cf345> in <module>()
----> 1 model_cEXT.predict_proba(X_test)

AttributeError: 'Sequential' object has no attribute 'predict_proba'

编辑:我需要 sklearn 之类的 predict_proba 输出,可视化需要它

skplt.metrics.plot_precision_recall_curve(y_test['cEXT'].values, y_prob)
plt.title('Precision-Recall Curve - cEXT')
plt.show()

最佳答案

改用这段代码

predict_prob=model.predict([testa,testb])

predict_classes=np.argmax(predict_prob,axis=1)

关于tensorflow - 属性错误 : 'Sequential' object has no attribute 'predict_proba' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68971378/

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