python 参数一样结果不一样_优化Keras的超参数:相同参数的结果不同

在尝试优化Keras模型的超参数时,作者使用GridSearchCV进行交叉验证,发现不同运行间虽然参数配置相同,但最佳参数和性能得分不一致。具体表现为第一次最佳参数为(epochs=150, batch_size=10),得分0.31568,而第二次最佳参数为(epochs=100, batch_size=20),得分0.31369。尽管数据集大小为((1001, 10), (1001, 4))保持不变,结果仍然出现变化。" 132660782,19694809,选择Python稳定版本:Python 3.9的可靠性与兼容性,"['Python', '开发', '版本管理', '代码兼容性', '软件工程']
摘要由CSDN通过智能技术生成

我试着调整超参数def create_model():

# create model

model = Sequential()

model.add(Dense(12, input_dim=10, kernel_initializer='uniform', activation='relu'))

model.add(Dense(4, kernel_initializer='uniform', activation='sigmoid'))

# Compile model

model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy'])

return model

# create model

model = KerasClassifier(build_fn=create_model, verbose=0)

cv = KFold(n_splits=5, shuffle=True, random_state=1)

# grid search epochs, batch size and optimizer

epochs = [ 100, 150, 170, 200, 250]

batches = [ 5, 10, 20, 25, 30]

param_grid = dict(epochs=epochs, batch_size=batches)

grid = GridSearchCV(estimator=model, param_grid=param_grid, cv = cv)

然后适合

^{pr2}$

我得到了grid_result.best_params_, grid_result.best_score_

({'batch_size': 10, 'epochs': 150}, 0.31568432165371191)

在那之后,我使都一样并且得到grid_result.best_params_, grid_result.best_score_

({'batch_size': 20, 'epochs': 100}, 0.31368631761629029)

有什么问题吗?数据集大小X_train.shape, y_train.shape

((1001, 10), (1001, 4))

我们一定会得到相同的结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值