Can someone tell me if this is the correct implementation of SGD logistic regression in Java? I'm trying to follow this based on the description on the coursera video. Thanks.

    double intercept = 0.0;
    double weights[] = new double[X[0].length];
    for (int numIterations = 0; numIterations < 500000; numIterations++)
    {
        for (int item = 0; item < X.length; item++)
        {
            double[] currentItem = X[item];

            double z = intercept;
            for (int j = 0; j < currentItem.length; j++)
            {
                z += (weights[j] * currentItem[j]);
            }

            double adjust = 0.0001 * ((1.0 / (1.0 + Math.exp(-z))) - y[item]); // alpha * (h(x) - y)

            // adjust all of the weights at the same time
            intercept = intercept - adjust;
            for (int j = 0; j < currentItem.length; j++)
            {
                weights[j] = weights[j] - (adjust * currentItem[j]);
            }

        }
    }

asked Aug 25 '13 at 13:01

soybie's gravatar image

soybie
1111

Be the first one to answer this question!
toggle preview

powered by OSQA

User submitted content is under Creative Commons: Attribution - Share Alike; Other things copyright (C) 2010, MetaOptimize LLC.