首页 > 解决方案 > 为 scikit-learn 安装轮子时的弃用警告

问题描述

我是 Python 新手。有人可以告诉我应该如何解决这个错误。

C:\Users\admin\Desktop\Hiwi\Python Programs>py TSP.py
C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sklearn\externals\six.py:28: DeprecationWarning: The module is deprecated in version 0.21 and will be removed in version 0.23 since we've dropped support for Python 2.7. Please rely on the official version of six (https://pypi.org/project/six/).
  warnings.warn("The module is deprecated in version 0.21 and will be removed "
Traceback (most recent call last):
  File "TSP.py", line 4, in <module>
    fitness_coords = mlrose.TravellingSales(coords=coords_lists)
NameError: name 'coords_lists' is not defined

先感谢您。

标签: pythondeprecation-warning

解决方案


首先,这不仅仅是一个错误warning。接下来,看来py TSP.py您实际上是在尝试运行 python 脚本。

在第 4 行中,之前fitness_coords = mlrose.TravellingSales(coords=coords_lists)似乎coords_lists没有定义。

你想运行这个???

然后你需要在TSP.py文件中有这样的东西:

# Create list of city coordinates
coords_list = [(1, 1), (4, 2), (5, 2), (6, 4), (4, 4), (3, 6), (1, 5), (2, 3)]

# Initialize fitness function object using coords_list
fitness_coords = mlrose.TravellingSales(coords = coords_list)

对于警告,请在.py文件中使用:

import something

def warn(*args, **kwargs):
    pass
import warnings
warnings.warn = warn

推荐阅读