我正在解决多类分类问题,并尝试使用广义Boosted模型(R中的gbm包).我遇到的问题:插入符号的train功能method="gbm"似乎不能正确处理多类数据.下面给出一个简单的例子.
library(gbm)
library(caret)
data(iris)
fitControl <- trainControl(method="repeatedcv",
number=5,
repeats=1,
verboseIter=TRUE)
set.seed(825)
gbmFit <- train(Species ~ ., data=iris,
method="gbm",
trControl=fitControl,
verbose=FALSE)
gbmFit
Run Code Online (Sandbox Code Playgroud)
输出是
+ Fold1.Rep1: interaction.depth=1, shrinkage=0.1, n.trees=150
predictions failed for Fold1.Rep1: interaction.depth=1, shrinkage=0.1, n.trees=150
- Fold1.Rep1: interaction.depth=1, shrinkage=0.1, n.trees=150
+ Fold1.Rep1: interaction.depth=2, shrinkage=0.1, n.trees=150
...
+ Fold5.Rep1: interaction.depth=3, shrinkage=0.1, n.trees=150
predictions failed for Fold5.Rep1: interaction.depth=3, shrinkage=0.1, n.trees=150
- Fold5.Rep1: interaction.depth=3, shrinkage=0.1, n.trees=150
Aggregating results
Selecting tuning parameters
Fitting interaction.depth = numeric(0), n.trees = numeric(0), shrinkage = …Run Code Online (Sandbox Code Playgroud) 在 TF 1.x 中,可以使用自定义变量构建层。下面是一个例子:
import numpy as np
import tensorflow as tf
def make_custom_getter(custom_variables):
def custom_getter(getter, name, **kwargs):
if name in custom_variables:
variable = custom_variables[name]
else:
variable = getter(name, **kwargs)
return variable
return custom_getter
# Make a custom getter for the dense layer variables.
# Note: custom variables can result from arbitrary computation;
# for the sake of this example, we make them just constant tensors.
custom_variables = {
"model/dense/kernel": tf.constant(
np.random.rand(784, 64), name="custom_kernel", dtype=tf.float32),
"model/dense/bias": tf.constant(
np.random.rand(64), name="custom_bias", dtype=tf.float32), …Run Code Online (Sandbox Code Playgroud) 我正在使用tf.kerasTensorFlow 1.14.0。我已经实现了一个计算量非常大的自定义指标,如果我只是将它添加到作为model.compile(..., metrics=[...]).
如何让 Keras 在训练迭代期间跳过度量的计算,但在每个时期结束时根据验证数据(并打印)计算它?