【问题标题】:How to set arguments of 'build_fn' of Keras's scikit learn API separately?如何分别设置 Keras 的 scikit learn API 的“build_fn”参数?
【发布时间】:2019-01-16 03:24:13
【问题描述】:
def create_model(input_shape, lr):
    model = Sequential()
    model.add(Dense(20, input_shape, 'relu'))
    opt = optimizers.Adam(lr)
    model.compile(loss='binary_crossentropy', optimizer=opt)
    return model

clf = KerasClassifier(build_fn= create_model, input_shape=10,batch_size=25)
list_of_learning_rates = [1e-3,1e-2]
list_of_epochs = [50,100]
gridSearch(clf, list_of_learning_rates, list_of_epochs)

由于特定原因,我编写了自己的网格搜索代码,它的编写方式是我必须初始化我正在使用的分类器并将分类器传递给网格搜索函数,并带有参数列表。示例是更多。如何在gridSearch 函数中专门设置epochslr 参数?我正在考虑使用functools.partial,但我不确定如何使用:functools.partial(clf, lr=list_of_learning_rates[0], epcohs=list_of_epochs[0]),但clf 不是一个函数,所以这不起作用。

【问题讨论】:

    标签: python scikit-learn keras callable


    【解决方案1】:

    我找到了我的问题的答案。我可以使用clfset_params() 函数。比如d={'epochs':10, 'lr':1e-3},我可以运行这个来设置参数:clf.set_params(**d)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-16
      • 1970-01-01
      • 2018-03-18
      • 2016-09-10
      • 2013-07-16
      • 2020-02-20
      • 1970-01-01
      相关资源
      最近更新 更多