Hi there!
I have trouble plotting a 3-D boundary for SVMs.
Here is the code that works with SVM:
from sklearn import svm
import numpy as np
from sklearn.datasets import make_classification
from sklearn.svm import SVC
X, y1 = make_classification(n_samples=100, n_features=3, n_redundant=1, n_informative=2,
random_state=332, n_clusters_per_class=1, hypercube=False)
clf = SVC(C=10, cache_size=200, class_weight=None, coef0=6,
decision_function_shape='ovr', degree=6, gamma=0.30000000000000004,
kernel='poly', max_iter=-1, probability=False, random_state=None,
shrinking=True, tol=0.001, verbose=False)
clf.fit(X,y)
X_0 = np.array([x for idx, x in enumerate(X) if y[idx]==0 and not x in clf.support_vectors_])
X_1 = np.array([x for idx, x in enumerate(X) if y[idx]==1 and not x in clf.support_vectors_])
And here the part to build just separately test and trained data:
import plotly
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
plotly.tools.set_credentials_file(username='KristinaKulivnyk', api_key='n1y0rfzdEbEjx63HoUx5')
trace1 = go.Scatter3d(
x=X_0[:, 0],
y=X_0[:, 1],
z=X_0[:, 2],
mode='markers',
marker=dict(
size=12,
color=z, # set color to an array/list of desired values
colorscale='Greys', # choose a colorscale
opacity=0.8
)
)
trace2 = go.Scatter3d(
x=X_1[:, 0],
y=X_1[:, 1],
z=X_1[:, 2],
mode='markers',
marker=dict(
size=12,
color=z, # set color to an array/list of desired values
colorscale='Reds', # choose a colorscale
opacity=0.8
)
)
data = [trace1, trace2]
layout = go.Layout(
margin=dict(
l=0,
r=0,
b=0,
t=0
)
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='3d-scatter-colorscale')
But it is not quite clear how to build a 3-D decision boundary. I’ll appreciate any help.