Commits

Anonymous committed 00a6679

...

  • Participants
  • Parent commits 77e0646

Comments (0)

Files changed (2)

File ca2/Intro_3.ipynb

+{
+ "metadata": {
+  "name": "Intro_3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+  {
+   "cells": [
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "import numpy as np\n",
+      "import matplotlib.pyplot as plt\n",
+      "from sklearn import datasets, neighbors, metrics, cross_validation\n",
+      "\n",
+      "import warnings\n",
+      "warnings.filterwarnings('default')"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 1
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    }
+   ],
+   "metadata": {}
+  }
+ ]
+}

File ca2/intro_2.ipynb

      "input": [
       "def combine_knn(knn_list, score_list, ij_list):\n",
       "    def predict(X):\n",
+      "        # \u0441\u0442\u0440\u043e\u0438\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432\n",
       "        Y_list = []\n",
       "        for knn, ij in zip(knn_list, ij_list):\n",
-      "            i, j = ij\n",
-      "            U = np.c_[X[:,i], X[:,j]]\n",
-      "            Y = knn.predict(U)\n",
-      "            Y_list.append(Y)\n",
-      "        Sa = np.array(score_list)\n",
-      "        Ya = np.column_stack(Y_list)\n",
-      "        Y1 = np.inner(Ya == 0, Sa)\n",
-      "        Y2 = np.inner(Ya == 1, Sa)\n",
-      "        Y3 = np.inner(Ya == 2, Sa)\n",
-      "        Yz = np.column_stack([Y1, Y2, Y3])\n",
-      "        Y = np.argmax(Yz, axis=1)\n",
+      "            i, j = ij          # \u043f\u0430\u0440\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u0438\u043b\u0441\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\n",
+      "            Xi = X[:, i]       # i-\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446\n",
+      "            Xj = X[:, j]       # j-\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446\n",
+      "            U = np.c_[Xi, Xj]  # \u0441\u0442\u0440\u043e\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432  i \u0438 j\n",
+      "            Y = knn.predict(U) # \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430\n",
+      "            Y_list.append(Y)   # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a \u0441\u043f\u0438\u0441\u043a\u0443\n",
+      "        Sa = np.array(score_list) # \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\n",
+      "        Ya = np.column_stack(Y_list) # \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043a\u0430\u043a \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0432 \u043d\u043e\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443\n",
+      "        Ya_0 = Ya == 0 # \u0441\u0442\u0440\u043e\u0438\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u043b\u0430\u0441\u0441\u0443 0\n",
+      "        Ya_1 = Ya == 1 # \u0441\u0442\u0440\u043e\u0438\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u043b\u0430\u0441\u0441\u0443 1\n",
+      "        Ya_2 = Ya == 2 # \u0441\u0442\u0440\u043e\u0438\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u043b\u0430\u0441\u0441\u0443 2\n",
+      "        Y1 = np.inner(Ya_0, Sa) # \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u044b\u0445 \u0441\u0443\u043c\u043c \u0433\u043e\u043b\u043e\u0441\u043e\u0432 \u0437\u0430 \u043a\u043b\u0430\u0441\u0441 0\n",
+      "        Y2 = np.inner(Ya_1, Sa) # \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u044b\u0445 \u0441\u0443\u043c\u043c \u0433\u043e\u043b\u043e\u0441\u043e\u0432 \u0437\u0430 \u043a\u043b\u0430\u0441\u0441 1\n",
+      "        Y3 = np.inner(Ya_2, Sa) # \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u044b\u0445 \u0441\u0443\u043c\u043c \u0433\u043e\u043b\u043e\u0441\u043e\u0432 \u0437\u0430 \u043a\u043b\u0430\u0441\u0441 2\n",
+      "        Yz = np.column_stack([Y1, Y2, Y3]) # \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0433\u043e\u043b\u043e\u0441\u043e\u0432 \u0437\u0430 \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u0430\u043a \u043a\u043e\u043b\u043e\u043d\u043a\u0438, \u0432 \u043e\u0434\u043d\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0443\n",
+      "        Y = np.argmax(Yz, axis=1) # \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0443\u043c\u043c\u043e\u0439 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\n",
       "        return Y\n",
       "    return predict\n",
       "\n",