{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n=========================================================\nSparsity Example: Fitting only features 1  and 2\n=========================================================\n\nFeatures 1 and 2 of the diabetes-dataset are fitted and\nplotted below. It illustrates that although feature 2\nhas a strong coefficient on the full model, it does not\ngive us much regarding `y` when compared to just feature 1\n\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "print(__doc__)\n\n\n# Code source: Ga\u00ebl Varoquaux\n# Modified for documentation by Jaques Grobler\n# License: BSD 3 clause\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom mpl_toolkits.mplot3d import Axes3D\n\nfrom sklearn import datasets, linear_model\n\ndiabetes = datasets.load_diabetes()\nindices = (0, 1)\n\nX_train = diabetes.data[:-20, indices]\nX_test = diabetes.data[-20:, indices]\ny_train = diabetes.target[:-20]\ny_test = diabetes.target[-20:]\n\nols = linear_model.LinearRegression()\nols.fit(X_train, y_train)\n\n\n# #############################################################################\n# Plot the figure\ndef plot_figs(fig_num, elev, azim, X_train, clf):\n    fig = plt.figure(fig_num, figsize=(4, 3))\n    plt.clf()\n    ax = Axes3D(fig, elev=elev, azim=azim)\n\n    ax.scatter(X_train[:, 0], X_train[:, 1], y_train, c='k', marker='+')\n    ax.plot_surface(np.array([[-.1, -.1], [.15, .15]]),\n                    np.array([[-.1, .15], [-.1, .15]]),\n                    clf.predict(np.array([[-.1, -.1, .15, .15],\n                                          [-.1, .15, -.1, .15]]).T\n                                ).reshape((2, 2)),\n                    alpha=.5)\n    ax.set_xlabel('X_1')\n    ax.set_ylabel('X_2')\n    ax.set_zlabel('Y')\n    ax.w_xaxis.set_ticklabels([])\n    ax.w_yaxis.set_ticklabels([])\n    ax.w_zaxis.set_ticklabels([])\n\n#Generate the three different figures from different views\nelev = 43.5\nazim = -110\nplot_figs(1, elev, azim, X_train, ols)\n\nelev = -.5\nazim = 0\nplot_figs(2, elev, azim, X_train, ols)\n\nelev = -.5\nazim = 90\nplot_figs(3, elev, azim, X_train, ols)\n\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
}