【问题标题】:How to examine the feature weights of a Tensorflow LinearClassifier?如何检查 Tensorflow 线性分类器的特征权重?
【发布时间】:2023-03-09 03:45:01
【问题描述】:

我正在尝试了解Large-scale Linear Models with TensorFlow 文档。文档激励这些模型如下:

线性模型比神经模型更容易解释和调试 网。 您可以检查分配给每个功能的权重来计算 找出对预测影响最大的因素。

所以我从随附的TensorFlow Linear Model Tutorial 中运行了扩展代码示例。特别是,我运行了example code from GitHub,并将model-type 标志设置为wide。这正确运行并生成了 accuracy: 0.833733,类似于 Tensorflow 网页上的 accuracy: 0.83557522

该示例使用tf.estimator.LinearClassifier 来训练权重。然而,与引用的能够检查权重的动机相比,我在LinearClassifier documentation 中找不到任何函数来实际提取训练的权重。

问题:如何访问tf.estimator.LinearClassifier 中各个特征列的训练权重?我希望能够提取 NumPy 数组中的所有权重。

注意:我来自 R 环境,其中线性回归/分类模型具有 coefs 方法来提取学习权重。我希望能够在相同的数据集上比较 R 和 TensorFlow 中的线性模型。

【问题讨论】:

    标签: python machine-learning tensorflow classification linear-regression


    【解决方案1】:

    使用 Estimator 训练模型后,您可以使用 tf.train.load_variable 从检查点检索权重。您可以使用tf.train.list_variables 查找模型权重的名称。

    还有计划直接在 Estimator 中添加此支持。

    【讨论】:

    • 谢谢,您有关于将其添加到 Estimator 的讨论链接吗?
    • tf.estimators 现在直接支持此功能:wt_names = model.get_variable_names() wt_vals = [model.get_variable_value(name) for name in wt_names]
    猜你喜欢
    • 2019-12-04
    • 1970-01-01
    • 2017-08-15
    • 2016-03-29
    • 2020-12-22
    • 2023-01-15
    • 2012-06-19
    • 2013-04-01
    • 2014-02-11
    相关资源
    最近更新 更多