1

I'm using Python 3.5.2 on Ubuntu 16.04.

I've installed sklearn using..

sudo apt install python-sklearn

and mlxtend using...

sudo pip3 install mlxtend

I'm trying to run the basic Iris example found on the Internet, but I am getting an error as soon as I try to import plot_decision_regions from mlxtend.plotting:

from mlxtend.plotting import plot_decision_regions


Traceback (most recent call last):
  File "scripts/machine.learning.py", line 6, in <module>
    from mlxtend.plotting import plot_decision_regions
  File "/usr/local/lib/python3.5/dist-packages/mlxtend/plotting/__init__.py", line 15, in <module>
    from .heatmap import heatmap
  File "/usr/local/lib/python3.5/dist-packages/mlxtend/plotting/heatmap.py", line 74
    raise AssertionError(f'len(row_names) (got {len(row_names)})'
                                                                ^
SyntaxError: invalid syntax
desertnaut
  • 57,590
  • 26
  • 140
  • 166
deanresin
  • 1,466
  • 2
  • 16
  • 31
  • Including a whole bunch of code which is never executed (and hence it's irrelevant to your issue) obscures the problem, creates unnecessary clutter, and is certainly not helpful for possible respondents (edited to remove excess code). – desertnaut Jul 31 '19 at 08:56

2 Answers2

2

I had the same error, just upgrade to python3.7 the real error is

python 3.5 does not support f prefix

upgrade using conda

conda install -c anaconda python=3.7

and then update all depencies

conda update --all
0

I'm not seeing the same error as you, but try remove legend=range(105, 150) from plot_decision_regions i.e.

plot_decision_regions(x_combined, y_combined, clf=tree)

I'm using the latest current sklearn, i.e.

import sklearn
sklearn.__version__

'0.21.3'

Perhaps remove that version

sudo apt-get remove python-sklearn

Then install via pip, i.e.

pip3 install scikit-learn
David Waterworth
  • 2,214
  • 1
  • 21
  • 41
  • It is apparent from the error message that the issue is at `from mlxtend.plotting import plot_decision_regions`, not in the code itself - pls see edited code in OP – desertnaut Jul 31 '19 at 09:00
  • Not sure then, only other difference is I'm using python 3.7 and ubuntu 18.04 but I doubt that's the cause. It could possibly be related to your matplotlib version? – David Waterworth Jul 31 '19 at 22:58