【问题标题】:Loss, metrics, and scoring in KerasKeras 中的损失、指标和评分
【发布时间】:2018-12-17 19:05:52
【问题描述】:

loss、metrics 和scoring 在构建keras 模型方面有什么区别?它们应该不同还是相同?在一个典型的模型中,我们使用所有三个 forGridSearchCV。

这是一个典型的回归模型的快照,它使用了这三个模型。

def create_model():

 model = Sequential()
 model.add(Dense(12, input_dim=1587, activation='relu'))
 model.add(Dense(1, activation='sigmoid'))

 model.compile(loss='mean_squared_error', optimizer='adam', metrics=['mean_squared_error'])
 return model

model = KerasRegressor(build_fn=create_model, verbose=0)
batch_size = [10, 20, 40, 60, 80, 100]
epochs = [10, 50, 100]
param_grid = dict(batch_size=batch_size, epochs=epochs)
grid = GridSearchCV(estimator=model,param_grid=param_grid, scoring='r2' n_jobs=-1)
grid_result = grid.fit(X, Y)

【问题讨论】:

    标签: tensorflow machine-learning scikit-learn keras grid-search


    【解决方案1】:

    不,它们都是在您的代码中用于不同目的的不同事物。

    您的代码中有两个部分。

    1) Keras 部分:

     model.compile(loss='mean_squared_error', 
                   optimizer='adam', 
                   metrics=['mean_squared_error'])
    

    a)loss:在Compilation section of the documentation here,你可以看到:

    损失函数是模型试图达到的目标 最小化。

    所以这实际上是与optimizer 一起使用来实际训练模型

    b)metrics:根据documentation:

    度量函数类似于损失函数,除了 训练模型时不使用评估指标的结果。

    这仅用于报告指标,以便使用(您)可以判断模型的性能。它不会影响模型的训练方式。

    2) 网格搜索部分:

    scoring:再次检查the documentation

    单个字符串或可调用来评估测试集上的预测。

    这用于查找您在param_grid 中定义的参数组合,它给出了最好的score。

    它们可以很好地(在大多数情况下)不同,这取决于你想要什么。

    【讨论】:

    • 是否有任何理由使用与损失不同的指标?
    • 拿一个分类问题。您的损失很可能是分类交叉熵,但最终您会想知道您的模型是否给了您正确的答案,因此您的指标将是模型的准确性。分类交叉熵和准确性是相关的,但您仍然需要优化和评估您的模型。
    猜你喜欢
    • 2019-04-30
    • 1970-01-01
    • 2019-04-28
    • 1970-01-01
    • 2021-05-07
    • 2021-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多