建立loss
模型时,metrics
,scoring
和keras
有什么区别?它们应该不同还是相同?在一个典型的模型中,我们将所有三个都用于GridSearchCV
。
这是使用这三个模型的典型回归模型的快照。
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)
最佳答案
不,它们都是代码中用于不同目的的不同事物。
您的代码分为两部分。
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
。根据您的需要,它们可以很好地(在大多数情况下)有所不同。
关于tensorflow - Keras的损失,指标和得分,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51256695/