Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 试图清理最近邻地块的边界_Python_Matplotlib_Scikit Learn_Nearest Neighbor - Fatal编程技术网

Python 试图清理最近邻地块的边界

Python 试图清理最近邻地块的边界,python,matplotlib,scikit-learn,nearest-neighbor,Python,Matplotlib,Scikit Learn,Nearest Neighbor,在用python测试之前,我正在用一些训练数据绘制一个小图。我的情节现在看起来像这样。训练数据来自傅立叶空间中的字母图像,我对其进行了屏蔽,以产生不同的字母值 对我来说,这些边界看起来不太理想,我不确定如何着手修复它们,使红点和蓝点有自己独特的区域。以下是我正在使用的代码: X = np.matrix(X) #knn = KNeighborsClassifier(n_neighbors=3) y = [0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,

在用python测试之前,我正在用一些训练数据绘制一个小图。我的情节现在看起来像这样。训练数据来自傅立叶空间中的字母图像,我对其进行了屏蔽,以产生不同的字母值

对我来说,这些边界看起来不太理想,我不确定如何着手修复它们,使红点和蓝点有自己独特的区域。以下是我正在使用的代码:

X = np.matrix(X)
#knn = KNeighborsClassifier(n_neighbors=3)
y = [0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2]

h = 0.2  # step size in the mesh


# Create color maps
cmap_light = ListedColormap(['#FFAAAA', '#AAFFAA', '#AAAAFF'])
cmap_bold = ListedColormap(['#FF0000', '#00FF00', '#0000FF'])

n_neighbors = 10
for weights in ['uniform', 'distance']:
    # we create an instance of Neighbours Classifier and fit the data.
    clf = KNeighborsClassifier(n_neighbors, weights=weights)
    clf.fit(X, y)


    # Plot the decision boundary. For that, we will assign a color to each
    # point in the mesh [x_min, x_max]x[y_min, y_max].
    x_min, x_max = X[:, 0].min() - 30, X[:, 0].max() + 20
    y_min, y_max = X[:, 1].min() - 5, X[:, 1].max() + 5
    xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
                         np.arange(y_min, y_max, h))
    Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])

    # Put the result into a color plot
    Z = Z.reshape(xx.shape)
    plt.figure()
    plt.pcolormesh(xx, yy, Z, cmap=cmap_light)

    # Plot also the training points

    plt.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap_bold)
    plt.xlim(xx.min(), xx.max())
    plt.ylim(yy.min(), yy.max())
    plt.title("3-Class classification (k = %i, weights = '%s')"
              % (n_neighbors, weights))

plt.show()

这是一种寻找不同数据点来分类数据的情况吗?或者有没有办法改变这些决策边界的形成方式?任何帮助都将不胜感激,如果我在某些事情上太含糊,请告诉我。提前谢谢

我认为matplotlib只是在绘制它被要求绘制的内容。所以我用scikit学习标签标记了这个问题。我认为matplotlib只是在绘制它被要求绘制的内容。所以我用scikit学习标签标记了这个问题。