42-AI / bootcamp_machine-learning

Bootcamp to learn basics in Machine Learning
Other
205 stars 41 forks source link

Day 08 - ex06 : Loss function example error #229

Open cnstll opened 2 years ago

cnstll commented 2 years ago

The examples provided for the loss function pass X and Y as parameters while the loss function should really be applied to Y and Y_hat

Examples Examples with loss corrected:

    X = np.array([[1., 1., 2., 3.], [5., 8., 13., 21.], [3., 5., 9., 14.]])
    Y = np.array([[1], [0], [1]])
    mylr = MyLogisticRegression([2, 0.5, 7.1, -4.3, 2.09])
    # Example 0:
    Y_hat = mylr.predict_(X)
    print(Y_hat)
    # Output:
    array([[0.99930437],
            [1.        ],
            [1. ]])
    # Example 1:
    print(mylr.loss_(Y, Y_hat)) # HERE
    # Output:
    11.513157421577004
    # Example 2:
    mylr.fit_(X, Y)
    print(mylr.thetas)
    # Output:
    # array([[ 1.04565272],
    #        [ 0.62555148],
    #        [ 0.38387466],
    #        [ 0.15622435],
    #        [-0.45990099]])
    # Example 3:
    Y_hat = mylr.predict_(X)
    print(Y_hat)
    # Output:
    array([[0.72865802],
           [0.40550072],
           [0.45241588]])
    # Example 4:
    print(mylr.loss_(Y, Y_hat))  # HERE
    # Output:
    0.5432466580663214

Screenshots Screenshot of current examples section image

Fixed on:

cnstll commented 2 years ago

The issue is also present https://github.com/42-AI/bootcamp_machine-learning/blob/master/build/module08.pdf image