sách gpt4 ai đã đi

python - Keras 2.0.8 仅使用 Python 3.x 执行 1 个 epoch,使用 2.x 执行 10 个

In lại 作者:太空宇宙 更新时间:2023-11-04 02:33:41 27 4
mua khóa gpt4 Nike

如果我将它切换到 Python 2.x,它执行 10。这是为什么?

训练逻辑回归模型

                                 import keras.backend as K
from keras.models import Sequential
from keras.layers import Dense, Activation
from keras.optimizers import SGD
from sklearn.model_selection import train_test_split, cross_val_score

X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size = 0.3,
random_state = 42)

# NOTE: If I run this in Python 3.x, it only performs 1 Epoch
K.clear_session()

model = Sequential()
model.add(Dense(1, input_shape=(4,), activation='sigmoid'))

model.compile(loss = 'binary_crossentropy',
optimizer= 'sgd',
metrics = ['accuracy'])

# Saved the result of the fitting, to display the history as a data frame & see how the model does
history = model.fit (X_train, y_train)
result = model.evaluate(X_test, y_test)

Đầu ra:

Epoch 1/10
960/960 [==============================] - 0s - loss: 0.7943 - acc: 0.5219
Epoch 2/10
960/960 [==============================] - 0s - loss: 0.7338 - acc: 0.5469
Epoch 3/10
960/960 [==============================] - 0s - loss: 0.6847 - acc: 0.5688
Epoch 4/10
960/960 [==============================] - 0s - loss: 0.6446 - acc: 0.6177
Epoch 5/10
960/960 [==============================] - 0s - loss: 0.6113 - acc: 0.6719
Epoch 6/10
960/960 [==============================] - 0s - loss: 0.5832 - acc: 0.7000
Epoch 7/10
960/960 [==============================] - 0s - loss: 0.5591 - acc: 0.7177
Epoch 8/10
960/960 [==============================] - 0s - loss: 0.5381 - acc: 0.7365
Epoch 9/10
960/960 [==============================] - 0s - loss: 0.5196 - acc: 0.7542
Epoch 10/10
960/960 [==============================] - 0s - loss: 0.5031 - acc: 0.7688
32/412 [=>............................] - ETA: 0s

1 Câu trả lời

fit函数具有参数 epochs,默认值为 1.

fit(self, x=None, y=None, batch_size=None, epochs=1, verbose=1, callbacks=None, 
validation_split=0.0, validation_data=None, shuffle=True, class_weight=None,
sample_weight=None, initial_epoch=0, steps_per_epoch=None,
validation_steps=None)

但是,默认值过去是 10。查看 this commit ở giữa models.py ở giữa fit 的更改例如。您很可能使用旧版本的 Keras 和 Python 2。

关于python - Keras 2.0.8 仅使用 Python 3.x 执行 1 个 epoch,使用 2.x 执行 10 个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48452999/

27 4 0
Bài viết được đề xuất: node.js - $scope.$apply 和 ng-include
Bài viết được đề xuất: c - 在 C99 中读取制表符分隔的数据
Bài viết được đề xuất: node.js - 如何在 MongoDB 中批量保存对象数组?
Bài viết được đề xuất: c - strdup 和 strtok 导致的段错误
太空宇宙
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com