基本mlxtend示例给出无效的语法错误



我在Ubuntu上使用Python 3.5.2 16.04。

我已经使用..

安装了Sklearn

sudo apt install python-sklearn

和mlxtend使用...

sudo pip3 install mlxtend

我正在尝试运行Internet上的基本IRIS示例,但是一旦我尝试从mlxtend.plotting导入plot_decision_regions

我就会遇到错误
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

我有相同的错误,只需升级到python3.7真正的错误是

python 3.5不支持f前缀

使用conda

升级
conda install -c anaconda python=3.7

然后更新所有depencies

conda update --all

我没有看到与您相同的错误,但请尝试从plot_decision_regions删除legend=range(105, 150),即

plot_decision_regions(x_combined, y_combined, clf=tree)

我正在使用最新的当前Sklearn,即

import sklearn
sklearn.__version__

'0.21.3'

也许删除该版本

sudo apt-get remove python-sklearn

然后通过PIP安装,即

pip3 install scikit-learn

最新更新