How to plot 3-D boundary for any kernel SVM

@Aparna

To get a code working for you data, please, comment out these two lines:

tmp = np.linspace(-2,2,51)
x,y = np.meshgrid(tmp,tmp)

and replace them by:

xm, xM = X[:,0].min(), X[:, 0].max()
ym, yM = X[:,1].min(), X[:, 1].max()
x = np.linspace(xm, xM, 10)
y = np.linspace(ym, yM, 10)
x, y =np.meshgrid(x, y)

The last lines of code extracted the x- values, respectively y-values range. Then it is defined a meshgrid over the rectangle [xm, xM] x [ym, yM] and evaluated (via z(x,y) )the separating plane equation at the points of this grid, to get data for a go.Surface, that represents the plane.

I replaced the β€˜Greys’ colorscale with a simple one (there is no reason to color the separating plane darker in its upper part):
my_colorscale = [[0, β€˜rgb(230,230,230)’], [1, β€˜rgb(230,230,230)’]]`,
and added opacity =0.9:

fig.add_surface(x=x, y=y, z=z(x,y), colorscale=my_colorscale, showscale=False, opacity=0.9)
and finally updated layout to width=800, height=800.

1 Like