Keras输出层阶跃阈值

时间:2019-04-09 23:54:43

标签: keras neural-network sequential

我正在尝试构建Keras模型。

Sub original_sort_code()
    Dim a, i As Long
    With Cells(1).CurrentRegion
        a = .Value
        ReDim Preserve a(1 To UBound(a, 1), 1 To UBound(a, 2) + 1)
        With CreateObject("VBScript.RegExp")
            .Pattern = "\d+(\.\d+)?"
            For i = 2 To UBound(a, 1)
                If .test(a(i, 1)) Then a(i, UBound(a, 2)) = _
                Format$(.Execute(a(i, 1))(0), String(20, "0")) & a(i, 1)
            Next
        End With
        VSortM a, 2, UBound(a, 1), UBound(a, 2), 1
        .Value = a
    End With
End Sub

Private Sub VSortM(ary, LB, UB, ref, Optional ord As Boolean = 1)
    Dim M As Variant, i As Long, ii As Long, iii As Long, temp
    i = UB: ii = LB
    M = ary(Int((LB + UB) / 2), ref)
    Do While ii <= i
        If ord Then
            Do While ary(ii, ref) < M: ii = ii + 1: Loop
        Else
            Do While ary(ii, ref) > M: ii = ii + 1: Loop
        End If
        If ord Then
            Do While ary(i, ref) > M: i = i - 1: Loop
        Else
            Do While ary(i, ref) < M: i = i - 1: Loop
        End If
        If ii <= i Then
            For iii = LBound(ary, 2) To UBound(ary, 2)
                temp = ary(ii, iii): ary(ii, iii) = ary(i, iii): ary(i, iii) = temp
            Next
            ii = ii + 1: i = i - 1
         End If
    Loop
    If LB < i Then VSortM ary, LB, i, ref, ord
    If ii < UB Then VSortM ary, ii, UB, ref, ord
End Sub

尽管所需的输出应该是1或0。我知道由于随机梯度下降,我们无法做到这一点。但是,有没有可以设置阈值的阶跃层,所以我得到0或1作为输出?所需输出的形状为(1,25)

1 个答案:

答案 0 :(得分:0)

对于二进制输出,应在输出处使用sigmoid激活,并损失binary_crossentropy。然后,您可以简单地将四舍五入或将0.5的阈值应用于输出以获得二进制0/1值。