{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# sklearn_classification_iris\n",
    "\n",
    "https://morvanzhou.github.io/tutorials/machine-learning/sklearn/2-2-general-pattern/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn import datasets\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.neighbors import KNeighborsClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iris_X:\n",
      " [[ 5.1  3.5  1.4  0.2]]\n",
      "y_train:\n",
      " [2 2 0 2 2 1 0 0 0 0 0 0 1 0 2 2 1 0 0 2 1 2 2 0 1 2 1 2 0 1 2 2 2 2 2 1 2\n",
      " 0 0 1 2 1 1 1 2 1 0 2 1 1 1 2 0 2 0 1 2 0 0 1 0 0 2 0 0 2 0 1 2 2 0 0 1 2\n",
      " 2 0 1 0 1 1 1 2 2 2 1 0 2 0 0 2 0 2 2 1 0 2 2 1 1 1 1 1 0 2 0]\n"
     ]
    }
   ],
   "source": [
    "iris = datasets.load_iris()\n",
    "iris_X = iris.data\n",
    "iris_y = iris.target\n",
    "\n",
    "print('iris_X:\\n', iris_X[:1])\n",
    "\n",
    "X_train, X_test, y_train, y_test = train_test_split(\n",
    "    iris_X, iris_y, test_size=0.3)\n",
    "\n",
    "print('y_train:\\n', y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "predicted:\n",
      " [1 0 0 0 1 1 2 0 0 1 2 0 1 0 0 2 0 2 1 2 1 2 1 0 2 0 2 0 0 2 1 2 1 2 1 0 2\n",
      " 1 1 1 2 1 1 0 2]\n",
      "y:\n",
      " [1 0 0 0 1 1 2 0 0 1 2 0 1 0 0 1 0 2 1 2 1 2 1 0 2 0 2 0 0 1 1 2 1 2 1 0 2\n",
      " 1 1 1 2 1 1 0 1]\n"
     ]
    }
   ],
   "source": [
    "knn = KNeighborsClassifier()\n",
    "knn.fit(X_train, y_train)\n",
    "\n",
    "print('predicted:\\n', knn.predict(X_test))\n",
    "print('y:\\n', y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "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.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
