I used the following function for predicting probabilities with SGD in
multi-class case. But I very usually get "nan": RuntimeWarning: invalid
value encountered in divide prob /=
prob.sum(axis=1).reshape((prob.shape[0], -1)). and RuntimeWarning: overflow
encountered in exp  np.exp(prob, prob).

def predict_proba_lr(clf, DATA_X):
    prob = clf.decision_function(DATA_X)
    prob *= -1
    np.exp(prob, prob)
    prob += 1
    np.reciprocal(prob, prob)
    if len(prob.shape) == 1:
        return np.vstack([1 - prob, prob]).T
    else:
        prob /= prob.sum(axis=1).reshape((prob.shape[0], -1))
        return prob

Usage with:
model = SGDClassifier(loss="log", penalty="l1").fit(Lx, Ly)
probas = predict_proba_lr(model, U)

Why division by 0 happens here ?

2013/3/26 Lars Buitinck <l.j.buiti...@uva.nl>

> Please review https://github.com/scikit-learn/scikit-learn/pull/1814
>
> --
> Lars Buitinck
> Scientific programmer, ILPS
> University of Amsterdam
>
>
> ------------------------------------------------------------------------------
> Own the Future-Intel&reg; Level Up Game Demo Contest 2013
> Rise to greatness in Intel's independent game demo contest.
> Compete for recognition, cash, and the chance to get your game
> on Steam. $5K grand prize plus 10 genre and skill prizes.
> Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d
> _______________________________________________
> Scikit-learn-general mailing list
> Scikit-learn-general@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
>
------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire 
the most talented Cisco Certified professionals. Visit the 
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
Scikit-learn-general mailing list
Scikit-learn-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to