我试图使安德鲁的曲线与此代码一起工作:
import pandas as pd
from pandas.plotting import andrews_curves
def andrews_curves(df, class_column, normalize = False):
plt.style.use("ggplot")
plt.figure()
andrews_curves(df, class_column)
plt.draw()
andrews_curves(players, "RANK")
plt.show()
players
我的数据框在哪里。它放弃了警告:
More than 20 figures have been opened
然后:
RecursionError: maximum recursion depth exceeded while calling a Python object
这只发生在安德鲁曲线上,因为平行坐标在几乎相同的代码下工作得很好:
def parallel_coords(df, class_column):
plt.style.use("ggplot")
plt.figure()
parallel_coordinates(df, class_column = class_column, cols = list(df), alpha = 0.4)
plt.draw()
parallel_coords(players, "RANK")
plt.show()
我尝试使用clear('all')
、clf()
和cla()
方法,但它们的效果都为零。
您需要andrews_curves
在代码中重命名该函数。
似乎您想要做的是pandas.plotting.andrews_curves
在您自己的andrews_curves
函数中调用。
麻烦的是,一旦你定义了 andrews_curves,它就会替换同名的另一个对象,所以调用你的函数的效果是它递归地调用自己,直到它达到 python 的递归限制:
这不会影响parallel_coords
,因为您在其中调用的函数具有不同的名称。
简而言之,将您的 andrews_curves 函数重命名为其他名称:
def plot_andrews_curves(df, class_column, normalize = False):
plt.style.use("ggplot")
plt.figure()
andrews_curves(df, class_column)
plt.draw()
你不会有这个问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句