1
~\Anaconda3\lib\site-packages\sklearn\linear_model\stochastic_gradient.py in __init__(self, loss, penalty, alpha, l1_ratio, fit_intercept, max_iter, tol, shuffle, verbose, epsilon, n_jobs, random_state, learning_rate, eta0, power_t, early_stopping, validation_fraction, n_iter_no_change, class_weight, warm_start, average)
    469             validation_fraction=validation_fraction,
    470             n_iter_no_change=n_iter_no_change, warm_start=warm_start,
--> 471             average=average)
    472         self.class_weight = class_weight
    473         self.n_jobs = n_jobs

RecursionError: maximum recursion depth exceeded while calling a Python object

What is the problem causing this error?

Ali Atiia
  • 139
  • 7
  • 1
    We'd need more code to know for sure. Possibly, caused by an object that creates a reference to another new instance of the same class. This would cause infinite recursions – user1558604 Dec 11 '19 at 02:35
  • 1
    You need to provide more detail on how are using this function. Please follow the guideline https://stackoverflow.com/help/how-to-ask – work_in_progress Dec 11 '19 at 02:50
  • What happens when you run the command `$ python -c 'from sklearn.linear_model import SGDClassifier; svm = SGDClassifier(max_iter=2000, tol=0.2)'`? – charlesreid1 Dec 13 '19 at 21:46
  • raise the recursion error above – Stefanusray Dec 18 '19 at 07:47

1 Answers1

2

Python's default recursion limit is 3000 calls. So if you have a function like:

def compute_next_number(n):
    next = n - 1
    if next < 0:
        print("finished")
    else:
        return compute_next_number(next)

Then calling it like compute_next_number(100) will be OK (as it will call itself 100 times) but calling it as compute_next_number(100000) will not be OK (as it will call itself 3000 times and then on the 3001st recursion, Python will raise maximum recursion depth exceeded.

You can change the limit; see https://stackoverflow.com/a/3323013/412529.

jnnnnn
  • 3,889
  • 32
  • 37