简体   繁体   English

'numpy.ndarray':对象不可调用错误

[英]'numpy.ndarray' : object is not callable error

I am trying to visualize Logistic Regression on the training data set and here's the snippet of code when running encounters ('numpy.ndarray' object is not callable) error. 我试图在训练数据集上可视化Logistic回归,这是运行遭遇时的代码片段('numpy.ndarray'对象不可调用)错误。

How to fix this? 如何解决这个问题?

for i,j in enumerate(np.unique(Y_set)): plt.scatter(X_set(Y_set == j,0), X_set(Y_set == j, 1), c=ListedColormap(('red','green'))(i),label = j)

Welcome to SO. 欢迎来到SO。 It's hard to see where the error is because we have no idea what X_set and Y_set are... but I'm going to guess they are numpy.ndarrays. 很难看出错误在哪里,因为我们不知道X_set和Y_set是什么......但我猜它们是numpy.ndarrays。 If they are, the error is how you are referring to them in the scatter call. 如果是,则错误是您在分散调用中引用它们的方式。 You should use square brackets to index into your sets instead of the parentheses (which try to 'call' the object like a function). 您应该使用方括号来索引您的集合而不是括号(它试图像函数一样“调用”对象)。

for i,j in enumerate(np.unique(Y_set)):
    plt.scatter(X_set[Y_set == j,0], X_set[Y_set == j, 1],
                c=ListedColormap(('red','green'))(i),label = j)

尝试使用方括号来索引您的集合,这可能会起作用。

 plt.scatter(X_set[Y_set == j,0], X_set[Y_set == j, 1],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM