AttributeError: 'SGDClassifier' object has no attribute 'n_iter'

Hi Guys,

I keep getting the error:

AttributeError: 'SGDClassifier' object has no attribute 'n_iter'

in my web app. I have no idea why as SGDClassifier is able to understand 'n_iter' on my local machine running scikit-learn 0.19.0. I even opened up a bash shell and ran

pip --user --upgrade scikit-learn==0.19.0

and it upgraded successfully. Why would 'n_iter' be okay on my machine, but not here? This occurs when trying to update the SGDClassifier using 'partial_fit'.

Where are you running your script/code from? Is it a webapp? what version of python are you using?

I'm running python version 3.6.1 (via Anaconda). Yes, this is a web app run from /home/safesocialapp/application/. The app was working okay a few days ago, then I upgraded scikit-learn to the latest version. In the scikit-learn docs for SGDClassifier here

I just found for 'n_iter':

n_iter : int, optional The number of passes over the training data (aka epochs). Defaults to None. Deprecated, will be removed in 0.21. Changed in version 0.19: Deprecated

Why would it work in my 0.19.0 version, but not on pythonanywhere?

If you are running python3.6, were you using pip3.6 to install?

UPDATE1: So I just realized in the scikit-learn 0.19.0 docs for the SGDClassifier, there is now a 'max_iter' parameter which can be set instead of using 'n_iter'. However, if I create a new classifier where only 'max_iter' is set, it defaults to setting n_iter = None. Pythonanywhere still sees this 'n_iter' parameter and throws the same error as before.

UPDATE 2: I didn't use pip3.6 the first time. But now if I run

pip3.6 --user --upgrade scikit-learn==0.19.0

in the Bash Console, I get only: "usage pip <command> [options]"

If I just run pip3.6 install scikit-learn==0.19.0, it says:

Installing collected packages: scikit-learn
  Found existing installation: scikit-learn 0.18.1
    Uninstalling scikit-learn-0.18.1:

Traceback (most recent call last):
  File "/usr/lib/python3.6/", line 538, in move
    os.rename(src, real_dst)
OSError: [Errno 18] Invalid cross-device link: '/usr/local/lib/python3.6/dist-packages/scikit_learn-0.18.1.dist-info/DE
SCRIPTION.rst' -> '/tmp/pip-x0bf1otj-uninstall/usr/local/lib/python3.6/dist-packages/scikit_learn-0.18.1.dist-info/DESC
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/pip/", line 215, in main
    status =, args)
  File "/usr/local/lib/python3.6/dist-packages/pip/commands/", line 342, in run
  File "/usr/local/lib/python3.6/dist-packages/pip/req/", line 778, in install
  File "/usr/local/lib/python3.6/dist-packages/pip/req/", line 754, in uninstall
  File "/usr/local/lib/python3.6/dist-packages/pip/req/", line 115, in remove
    renames(path, new_path)
  File "/usr/local/lib/python3.6/dist-packages/pip/utils/", line 267, in renames
    shutil.move(old, new)
  File "/usr/lib/python3.6/", line 553, in move
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/dist-packages/scikit_learn-0.18.1.dist-info/DE

You were missing install in pip3.6 --user --upgrade scikit-learn==0.19.0

Should be pip3.6 install --user --upgrade scikit-learn==0.19.0

Ah man alright, thanks a lot!

I'm running into basically the same problem. I can run a web app locally on my machine, but when I try to run it on pythonanywhere I get the error message:

'AttributeError: 'SGDClassifier' object has no attribute 'n_iter'

I'm running Python 3.5 and scikit-learn 0.19.

Are you sure you've installed the right version of scikit-learn for python 3.5?

pip3.5 install --user --upgrade scikit-learn==0.19.0

Worked like a charm! Thanks for your help! It looks like I just needed to spend a little more time getting familiar with pythonanywhere's Dashboard.