上升a类

2024-10-02 12:29:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我构建了一个TensorFlow模型,它使用DNNClassifier将输入分为两类。在

我的问题是结果1在90-95%的情况下都会发生。因此,TensorFlow给了我所有预测的相同概率。在

我试图预测另一个结果(例如,结果2的假阳性比漏掉结果2的可能发生要好)。我知道在一般的机器学习中,在这种情况下,尝试提高结果2的权重是值得的。在

但是,我不知道如何在TensorFlow中实现这一点。documentation暗指它是可能的,但我找不到任何实际情况的例子。有没有人成功地做到了这一点,或者有人知道我在哪里可以找到一些示例代码或一个彻底的解释(我使用的是Python)?在

注意:我见过当有人使用TensorFlow的更基本的部分而不是一个估计器时,暴露的权重被操纵。出于维护的原因,我需要使用一个估计器。在


Tags: 代码模型机器示例tensorflowdocumentation情况原因
1条回答
网友
1楼 · 发布于 2024-10-02 12:29:13

^{}构造函数具有weight_column参数:

weight_column: A string or a _NumericColumn created by tf.feature_column.numeric_column defining feature column representing weights. It is used to down weight or boost examples during training. It will be multiplied by the loss of the example. If it is a string, it is used as a key to fetch weight tensor from the features. If it is a _NumericColumn, raw tensor is fetched by key weight_column.key, then weight_column.normalizer_fn is applied on it to get weight tensor.

所以只需添加一个新列,并为稀有类填充一些权重:

weight = tf.feature_column.numeric_column('weight')
...
tf.estimator.DNNClassifier(..., weight_column=weight)

[Update]下面是一个完整的工作示例:

^{pr2}$

相关问题 更多 >

    热门问题