0

I used scipy.optimize.fmin_bfgs to minimize the hinge loss (SVM). However, there are errors :

Divide-by-zero encountered: rhok assumed large.

Somebody said that “It had to do with the training data set”, anybody knows how to deal with the problem?

Opal
  • 81,889
  • 28
  • 189
  • 210
ryyral
  • 3
  • 1

1 Answers1

0

From the source code of scipy, rhok is,

rhok = 1.0 / (numpy.dot(yk, sk))

where both yk and sk depend on intput array x0.

A possible causes of this error may be a bad choice of initial condition x0 which tends to singularities in your function f. I would suggest plotting your function and maybe ensuring initial conditions are always away from possible divergent values. If this is part of a larger training routine, you could possibly use try and on catching an ZeroDivisionError try shifting the initial condition shifted by some amount. You may also find a different minimisation method is more robust from scipy minimize.

If you add the full_output option to scipy.optimize.fmin_bfgs it should give you more information about you particular case.

Ed Smith
  • 12,716
  • 2
  • 43
  • 55