gladiator
def better_plot_2d_svc_problem(X, y, svc=None):
'''
Plots a two-dimensional labeled dataset (X,y) and, if SVC object is given,
the decision surfaces (with margin as well).
'''
assert X.shape[1] == 2, "Dataset is not two-dimensional"
if svc!=None :
# Create a mesh to plot in
num = 200 # mesh resolution
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx, yy = np.meshgrid(np.linspace(x_min, x_max, num),
np.linspace(y_min, y_max, num))
XX=np.c_[xx.ravel(), yy.ravel()]
Z = better_svc_predict(svc, XX)
# Put the result into a color plot
Z = Z.reshape(xx.shape)
plt.contourf(xx, yy, Z, cmap=plt.cm.Pastel1)
# Plot the dataset
plt.scatter(X[:,0],X[:,1], c=y, cmap=plt.cm.Paired, marker='o', s=50)
def better_svc_predict(svc, X) :
h = svc.decision_function(X)
h[((h >= -1) & (h < -0.03)) | ((h > 0.03) & (h <= 1))] = 0.5
np.clip(h, -1, 1, out=h)
h[np.isclose(h, 0, atol=0.03)] = 5
return h