首页 > 解决方案 > 给出无效语法错误的基本 mlxtend 示例

问题描述

我在 Ubuntu 16.04 上使用 Python 3.5.2。

我已经安装了 sklearn 使用..

sudo apt install python-sklearn

和 mlxtend 使用...

sudo pip3 install mlxtend

我正在尝试运行在 Internet 上找到的基本 Iris 示例,但是当我尝试plot_decision_regions从以下位置导入时出现错误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

标签: pippython-3.5mlxtend

解决方案


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

python 3.5 不支持 f 前缀

使用 conda 升级

conda install -c anaconda python=3.7

然后更新所有依赖

conda update --all

推荐阅读