提问者:小点点

在我的逻辑回归程序中发现了一个错误


import numpy as np
import matplotlib.pyplot as plt

x,y,min_x,max_x,min_y,max_y,X,mesh_step_size= 10,10,2,9,1,7,10,10

def visualize(c,x,y):
  global min_x,max_x,min_y,max_y,X
  min_x,max_x = ...
  min_y,max_y = ...

x_vals,y_vals = np.meshgrid(np.arange(min_x,max_x, mesh_step_size))

    # Run the classifier on the mesh grid
output = c.predict(np.c_[x_vals.ravel(), y_vals.ravel()])
    # Reshape the output array
output = output.reshape(x_vals.shape)

    # Create a plot
plt.figure()
    # Choose a color scheme for the plot
plt.pcolormesh(x_vals, y_vals, output, cmap=plt.cm.gray)
    # Overlay the training points on the plot
plt.scatter(X[:, 0], X[:, 1], c=y, s=75, edgecolors='black',
linewidth=1, cmap=plt.cm.Paired)
    
# Specify the boundaries of the plot
plt.xlim(x_vals.min(), x_vals.max())
plt.ylim(y_vals.min(), y_vals.max())
    # Specify the ticks on the X and Y axes
plt.xticks((np.arange(int(X[:, 0].min() - 1), int(X[:, 0].max() + 1),
1.0)))
plt.yticks((np.arange(int(X[:, 1].min() - 1), int(X[:, 1].max() + 1),
1.0)))
plt.show()

我得到了这个错误,请帮助!!!!!!!!!!!! 回溯(最后一次调用):文件“d:\ai using python\logistic Regression 2.py”,第11行,x_vals,y_vals=np.meshgrid(np.arange(min_x,max_x,mesh_step_size))值错误:没有足够的值来解包(应为2,得到1)


共1个答案

匿名用户

您可能漏掉了np.meshgrid()的第二个参数。 更改:

x_vals,y_vals = np.meshgrid(np.arange(min_x,max_x, mesh_step_size)) 

致:

x_vals,y_vals = np.meshgrid(np.arange(min_x,max_x, mesh_step_size), np.arange(min_y, max_y, mesh_step_size))