Reputation: 1089
I'm trying to make a plot like this
With @Whole Brain's help, I've got this
with this code
X, y = make_circles(100, random_state=96867, factor=.1, noise=.1)
red_mask = y==0
plt.scatter(X[red_mask, 0], X[red_mask, 1], s=50, facecolors="none", edgecolors="r")
plt.scatter(X[~red_mask, 0], X[~red_mask, 1], s=50, marker="+", c="b")
However, when I tried to project the data to 3d
r = np.exp(-(X ** 2).sum(1))
ax = plt.subplot(projection='3d')
ax.scatter3D(X[red_mask, 0], X[red_mask, 1], facecolors="none", edgecolors="r")
ax.scatter3D(X[~red_mask, 0], X[~red_mask, 1], marker="+", c="b")
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('r')
plt.show()
I got this
which seems to mean that the radial basis function r = np.exp(-(X ** 2).sum(1))
doesn't work at all.
How do I get a right radial basis function that projects non-linearly separable data to linearly separable?
Upvotes: 0
Views: 171
Reputation: 3975
The main problem with your code is that the z
coordinates are never specified, and are set to 0 by default, thus giving a planar plot in 3d-space.
Changing the plotting instructions to the snippet below, which adds this third coordinate, produces a true 3d plot:
ax.scatter3D(X[red_mask, 0], X[red_mask, 1], r[red_mask], facecolors="none", edgecolors="r")
ax.scatter3D(X[~red_mask, 0], X[~red_mask, 1], r[~red_mask], marker="+", c="b")
To center the blue dots around 0, you'll want to change your kernel to r = np.exp((X ** 2).sum(1))
, as the negative exponential makes the points furthest from the center have lower r values. The final result is presented below, and makes the data linearly separable (y
was also changed to abs(y)
to better match the example image).
Upvotes: 1