小编mar*_*uan的帖子

使用带有gbm方法的插入符号进行多类分类

我正在解决多类分类问题,并尝试使用广义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)

r r-caret

15
推荐指数
1
解决办法
2万
查看次数

使用自定义张量作为变量的 TensorFlow 2.0 Keras 层

在 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)

python keras tensorflow tensorflow2.0

6
推荐指数
1
解决办法
2492
查看次数

如何让 Keras 仅对验证数据计算某个指标?

我正在使用tf.kerasTensorFlow 1.14.0。我已经实现了一个计算量非常大的自定义指标,如果我只是将它添加到作为model.compile(..., metrics=[...]).

如何让 Keras 在训练迭代期间跳过度量的计算,但在每个时期结束时根据验证数据(并打印)计算它?

python keras tensorflow

5
推荐指数
1
解决办法
1078
查看次数

标签 统计

keras ×2

python ×2

tensorflow ×2

r ×1

r-caret ×1

tensorflow2.0 ×1