安装scikitlearn的车轮时出现弃用警告

2024-05-23 19:50:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我是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

提前谢谢你。在


Tags: andtheinpyadminisversioncoords
2条回答

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

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

你想运行this???在

然后您需要在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文件中使用以下命令:

^{pr2}$

是否:

#!/usr/bin/env python -W ignore::DeprecationWarning

或与:

^{pr2}$

帮忙吗?在

您也可以尝试:

import warnings 
warnings.simplefilter("ignore", category=PendingDeprecationWarning) 
warnings.simplefilter("ignore", category=DeprecationWarning)

如果你张贴一个导致错误的确切代码的例子,我可以进一步更新我对你的确切情况的答案。上面两个中的一个警告。simplefilters应该为你忽略它。我已经从collections import Hashable测试过了,它可以工作,但是我不确定您使用什么import,但是请尝试一下,它应该可以工作

更新:看起来你有两件事要做,一是警告,二是错误。有了这个错误,就好像丢失了coords_list变量

相关问题 更多 >