{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n========================================================================\nIllustration of Gaussian process classification (GPC) on the XOR dataset\n========================================================================\n\nThis example illustrates GPC on XOR data. Compared are a stationary, isotropic\nkernel (RBF) and a non-stationary kernel (DotProduct). On this particular\ndataset, the DotProduct kernel obtains considerably better results because the\nclass-boundaries are linear and coincide with the coordinate axes. In general,\nstationary kernels often obtain better results.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "print(__doc__)\n\n# Authors: Jan Hendrik Metzen <jhm@informatik.uni-bremen.de>\n#\n# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom sklearn.gaussian_process import GaussianProcessClassifier\nfrom sklearn.gaussian_process.kernels import RBF, DotProduct\n\n\nxx, yy = np.meshgrid(np.linspace(-3, 3, 50),\n                     np.linspace(-3, 3, 50))\nrng = np.random.RandomState(0)\nX = rng.randn(200, 2)\nY = np.logical_xor(X[:, 0] > 0, X[:, 1] > 0)\n\n# fit the model\nplt.figure(figsize=(10, 5))\nkernels = [1.0 * RBF(length_scale=1.0), 1.0 * DotProduct(sigma_0=1.0)**2]\nfor i, kernel in enumerate(kernels):\n    clf = GaussianProcessClassifier(kernel=kernel, warm_start=True).fit(X, Y)\n\n    # plot the decision function for each datapoint on the grid\n    Z = clf.predict_proba(np.vstack((xx.ravel(), yy.ravel())).T)[:, 1]\n    Z = Z.reshape(xx.shape)\n\n    plt.subplot(1, 2, i + 1)\n    image = plt.imshow(Z, interpolation='nearest',\n                       extent=(xx.min(), xx.max(), yy.min(), yy.max()),\n                       aspect='auto', origin='lower', cmap=plt.cm.PuOr_r)\n    contours = plt.contour(xx, yy, Z, levels=[0.5], linewidths=2,\n                           colors=['k'])\n    plt.scatter(X[:, 0], X[:, 1], s=30, c=Y, cmap=plt.cm.Paired,\n                edgecolors=(0, 0, 0))\n    plt.xticks(())\n    plt.yticks(())\n    plt.axis([-3, 3, -3, 3])\n    plt.colorbar(image)\n    plt.title(\"%s\\n Log-Marginal-Likelihood:%.3f\"\n              % (clf.kernel_, clf.log_marginal_likelihood(clf.kernel_.theta)),\n              fontsize=12)\n\nplt.tight_layout()\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.6.7"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}