def svm_scenario(ax, x, y, zoom, kernel, C, title=None):
# Fit the model
clf = svm.SVC(kernel=kernel, C=C)
clf.fit(x, y)
# Plot results
if ax is not None:
# Prepare the figure
ax.grid(True)
ax.set_xlabel("$x_1$")
ax.set_ylabel("$x_2$")
if title is not None:
ax.set_title(title)
# Plot the decision function for each datapoint on the grid
xlim = [np.min(x[:,0])-zoom ,np.max(x[:,0])+zoom]
ylim = [np.min(x[:,1])-zoom ,np.max(x[:,1])+zoom]
xx, yy = np.meshgrid(np.linspace(xlim[0], xlim[1], 100),
np.linspace(ylim[0], ylim[1], 100))
zz = clf.decision_function(np.c_[xx.ravel(), yy.ravel()])
zz = zz.reshape(xx.shape)
# Plot model output for every pixel on the figure
ax.imshow(zz, interpolation='nearest', extent=(xx.min(), xx.max(), yy.min(), yy.max()), aspect='auto', origin='lower', cmap=plt.cm.PuOr_r)
# Plot decision boundary
ax.contour(xx, yy, zz, colors='r', levels=[0], alpha=0.75, linestyles=['-'])
ax.contour(xx, yy, zz, colors='b', levels=[-1, 1], alpha=0.5, linestyles=['--', '--'])
# Plot support vectors
ax.scatter(clf.support_vectors_[:, 0], clf.support_vectors_[:, 1], s=150, linewidth=1, facecolors='none', edgecolors='b', label="Support Vectors")
# Plot dataset
ax.scatter(x[:, 0], x[:, 1], s=30, c=y, cmap=plt.cm.Paired, edgecolors='k')
ax.legend()
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12,6))
fig.tight_layout()
svm_scenario(ax=ax1, x=dataset7_x_scaled, y=dataset7_y, zoom=1, kernel='rbf', C=1000, title="RBF Kernel, C=1000")
svm_scenario(ax=ax2, x=dataset7_x_scaled, y=dataset7_y, zoom=1, kernel='rbf', C=1, title="RBF Kernel, C=1")