text: ##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  ##          Nonlinear binary classification via kernel SVM on toy dataset
  ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
  #%% generate data
  import numpy as np
  import matplotlib.pyplot as plt
  from sklearn.datasets import make_circles
  
  X, y = make_circles(500, factor=.08, noise=.1, random_state=1)
  # note that y = 0,1 here and need not be +-1; SVM does internal transformation accordingly
  
  # plot
  plt.figure()
  plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Paired, edgecolors='k')
  plt.xlabel('x1')
  plt.ylabel('x2')
  plt.title('raw data')
  
  #%% SVM fit
  from sklearn.svm import SVC
  
  model = SVC(C=100, gamma=1)
  model.fit(X, y) # no scaling required as input variables are already scaled
  
  #%% plot model predictions
  y_predicted = model.predict(X)
  
  # plot
  plt.figure()
  plt.scatter(X[:, 0], X[:, 1], c=y_predicted, cmap=plt.cm.Paired, edgecolors='k')
  plt.xlabel('x1')
  plt.ylabel('x2')
  plt.title('predictions')
  
  #%% plot SVM boundaries
  plt.figure()
  plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Paired, edgecolors='k')
  plt.xlabel('x1')
  plt.ylabel('x2')
  
  # get axis limits
  ax = plt.gca()
  xlim = ax.get_xlim()
  ylim = ax.get_ylim()
  
  # create grid to evaluate model
  xx = np.linspace(xlim[0], xlim[1], 100)
  yy = np.linspace(ylim[0], ylim[1], 100)
  YY, XX = np.meshgrid(yy, xx)
  xy = np.vstack([XX.ravel(), YY.ravel()]).T
  Z = model.decision_function(xy).reshape(XX.shape)
  
  # plot decision boundary and supporting planes
  ax.contour(XX, YY, Z, levels=[-1, 0, 1], alpha=0.5, linestyles=['--', '-', '--'], colors=['green', 'red', 'green'])