Keras 中的损失、指标和评分
Loss, metrics, and scoring in Keras
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)
不,它们都是在您的代码中用于不同目的的不同东西。
您的代码中有两部分。
1) Keras 部分:
model.compile(loss='mean_squared_error',
optimizer='adam',
metrics=['mean_squared_error'])
a) loss
:在Compilation section of the documentation here中,你可以看到:
A loss function is the objective that the model will try to
minimize.
所以这实际上是与 optimizer
一起使用来实际训练模型
b) metrics
: 根据documentation:
A metric function is similar to a loss function, except that the
results from evaluating a metric are not used when training the model.
这仅用于报告指标,以便使用的(您)可以判断模型的性能。它不会影响模型的训练方式。
2) 网格搜索部分:
scoring
:再次检查the documentation
A single string or a callable to evaluate the predictions on the test set.
这用于查找您在 param_grid
中定义的参数组合,它给出了最好的 score
。
它们很可能(在大多数情况下)有所不同,具体取决于您的需要。
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)
不,它们都是在您的代码中用于不同目的的不同东西。
您的代码中有两部分。
1) Keras 部分:
model.compile(loss='mean_squared_error',
optimizer='adam',
metrics=['mean_squared_error'])
a) loss
:在Compilation section of the documentation here中,你可以看到:
A loss function is the objective that the model will try to minimize.
所以这实际上是与 optimizer
一起使用来实际训练模型
b) metrics
: 根据documentation:
A metric function is similar to a loss function, except that the results from evaluating a metric are not used when training the model.
这仅用于报告指标,以便使用的(您)可以判断模型的性能。它不会影响模型的训练方式。
2) 网格搜索部分:
scoring
:再次检查the documentation
A single string or a callable to evaluate the predictions on the test set.
这用于查找您在 param_grid
中定义的参数组合,它给出了最好的 score
。
它们很可能(在大多数情况下)有所不同,具体取决于您的需要。