gpt4 book ai didi

python - 为什么当我设置为 300 时,keras 只执行 10 个 epoch?

转载 作者:太空狗 更新时间:2023-10-30 01:41:23 24 4
gpt4 key购买 nike

我结合使用了 sklearn 和 Keras,以 Theano 作为后端运行。我正在使用以下代码-

import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import keras
from keras.callbacks import EarlyStopping, ModelCheckpoint
from keras.constraints import maxnorm
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.optimizers import SGD
from keras.wrappers.scikit_learn import KerasClassifier
from keras.constraints import maxnorm
from keras.utils.np_utils import to_categorical
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import StratifiedKFold
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
from sklearn.model_selection import train_test_split
from datetime import datetime
import time
from datetime import timedelta
from __future__ import division

seed = 7
np.random.seed(seed)

Y = data['Genre']
del data['Genre']
X = data

encoder = LabelEncoder()
encoder.fit(Y)
encoded_Y = encoder.transform(Y)

X = X.as_matrix().astype("float")

calls=[EarlyStopping(monitor='acc', patience=10), ModelCheckpoint('C:/Users/1383921/Documents/NNs/model', monitor='acc', save_best_only=True, mode='auto', period=1)]

def create_baseline():
# create model
model = Sequential()
model.add(Dense(18, input_dim=9, init='normal', activation='relu'))
model.add(Dense(9, init='normal', activation='relu'))
model.add(Dense(12, init='normal', activation='softmax'))
# Compile model
sgd = SGD(lr=0.01, momentum=0.8, decay=0.0, nesterov=False)
model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
return model

np.random.seed(seed)
estimators = []
estimators.append(('standardize', StandardScaler()))
estimators.append(('mlp', KerasClassifier(build_fn=create_baseline, nb_epoch=300, batch_size=16, verbose=2)))
pipeline = Pipeline(estimators)
kfold = StratifiedKFold(n_splits=10, shuffle=True, random_state=seed)
results = cross_val_score(pipeline, X, encoded_Y, cv=kfold, fit_params={'mlp__callbacks':calls})
print("Baseline: %.2f%% (%.2f%%)" % (results.mean()*100, results.std()*100))

当我开始运行这最后一部分时的结果是-

Epoch 1/10
...
Epoch 2/10

等等

它应该是 Epoch 1/300,当我在不同的笔记本上运行它时它工作得很好。

你们认为发生了什么事? np_epoch=300...

最佳答案

这是什么 Keras 版本?如果它大于 2.0,则 nb_epoch 被更改为仅 epochs。否则默认为 10。

关于python - 为什么当我设置为 300 时,keras 只执行 10 个 epoch?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43192447/

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