Skip to content

Commit

Permalink
better descr
Browse files Browse the repository at this point in the history
  • Loading branch information
justheuristic committed Jan 17, 2018
1 parent 20acf8a commit 9e84c74
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions 02_lab/lab1_regression_faces.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
Expand All @@ -24,7 +26,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from sklearn.datasets import fetch_olivetti_faces\n",
Expand All @@ -34,7 +38,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# @this code showcases matplotlib subplots. The syntax is: plt.subplot(height, width, index_starting_from_1)\n",
Expand All @@ -56,20 +62,24 @@
"\n",
"Let's solve the face reconstruction problem: given left halves of facex __(X)__, our algorithm shall predict the right half __(y)__. Our first step is to slice the photos into X and y using slices.\n",
"\n",
"__Slices in numpy:__\n",
"* In regular python, slice looks roughly like this: `a[2:5]` _(select elements from 2 to 5)_\n",
"* Numpy allows you to slice N-dimensional arrays along each dimension: [image_index, height, width]\n",
" * `data[:10]` - Select first 10 images\n",
" * `data[:, :10]` - For all images, select a horizontal stripe 10 pixels high at the top of the image\n",
" * `data[10:20, :, -25:-15]` - Take images [10, 11, ..., 19], for each image select a _vetrical stripe_ of width 10 pixels, 15 pixels away from the _right_ side.\n",
"\n",
"__Your task:__\n",
"\n",
"Let's use slices to select all __left image halves as X__ and all __right halves as y__."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# select left half of each face as X, right half as Y\n",
Expand All @@ -80,7 +90,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# If you did everything right, you're gonna see left half-image and right half-image drawn separately in natural order\n",
Expand All @@ -95,7 +107,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def glue(left_half,right_half):\n",
Expand All @@ -119,7 +133,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split\n",
Expand All @@ -133,7 +149,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from sklearn.linear_model import LinearRegression\n",
Expand All @@ -151,7 +169,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from sklearn.metrics import mean_squared_error\n",
Expand All @@ -163,7 +183,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Train predictions\n",
Expand All @@ -177,7 +199,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Test predictions\n",
Expand Down Expand Up @@ -247,7 +271,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"<YOUR CODE: fit the model on training set>"
Expand Down

0 comments on commit 9e84c74

Please sign in to comment.