【问题标题】:pybrain - ClassificationDataSet - how to understand the output when using SoftmaxLayerpybrain - ClassificationDataSet - 使用 SoftmaxLayer 时如何理解输出
【发布时间】:2015-03-25 03:32:12
【问题描述】:

我正在尝试使用 Pybrain 神经网络以及专门的 ClassificationDataSet 构建第一个分类器,但我不确定我是否完全理解它是否有效。

所以我有一个 pandas 数据框,其中包含 6 个特征列和 1 个类别标签列(Survived,只有 0 或 1)。

我用它构建了一个数据集:

ds = ClassificationDataSet(6, 1, nb_classes=2)
for i in df[['Gender', 'Pclass', 'AgeFill', 'FamilySize', 'FarePerPerson', 'Deck','Survived']].values:
    ds.addSample(tuple(i[:-1]), i[-1])
ds._convertToOneOfMany()
return ds

好的,我检查一下数据集的样子:

for i, m in ds:
    i, m


(array([ 1.,  3.,  2.,  2.,  1.,  8.]), array([1, 0]))
(array([ 0.,  1.,  1.,  2.,  0.,  2.]), array([0, 1]))

我已经有问题了。 [1,0] 或 [0,1] 是什么意思?它只是原始“幸存”列的“0”还是“1”?如何恢复原值?

稍后,当我完成网络训练时:

net = buildNetwork(6, 6, 2, hiddenclass=TanhLayer, bias=True,  outclass=SoftmaxLayer)
trainer = BackpropTrainer(net, ds)
trainer.trainEpochs(10)

我将尝试在我的另一个数据集(我想对其进行实际分类)上激活它,我将为 2 个输出神经元中的每一个获得一对激活结果,但是如何理解哪个输出神经元对应于哪个原始神经元班级?可能这是显而易见的事情,但不幸的是,我无法从文档中理解它。

【问题讨论】:

    标签: python pandas machine-learning classification pybrain


    【解决方案1】:

    好的,看起来 pybrain 使用位置来确定 (0,1) 或 (1,0) 表示哪个类。

    要返回原始 0 或 1 标记,您需要使用 argmax() 函数。因此,例如,如果我已经有一个训练有素的网络,并且我想在用于训练的相同数据上对其进行验证,我可以这样做:

    for inProp, num in ds:
        out = net.activate(inProp).argmax()
        if out == num.argmax():
            true+=1
        total+=1
    res = true/total
    

    inProp 看起来像我的激活输入值的元组,num - 预期的两个神经元输出((0,1) 或 (1,0))的元组,num.argmax() 会将其转换为只有 0 或 1 - 实际输出。

    我可能错了,因为这是一个纯粹的启发式方法,但它在我的示例中有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-08
      • 2011-12-30
      • 1970-01-01
      • 2013-06-06
      • 1970-01-01
      • 2015-03-01
      相关资源
      最近更新 更多