Skip to content

Commit

Permalink
reverting
Browse files Browse the repository at this point in the history
  • Loading branch information
kristychoi committed Mar 3, 2016
1 parent 142b724 commit b9f526e
Showing 1 changed file with 7 additions and 52 deletions.
59 changes: 7 additions & 52 deletions 4. K-means clustering and unsupervised learning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,11 @@
},
{
"cell_type": "code",
<<<<<<< HEAD
"execution_count": 10,
=======
"execution_count": 27,
>>>>>>> origin/master
"metadata": {
"collapsed": false
"collapsed": true
},
"outputs": [
{
"ename": "ImportError",
"evalue": "No module named 'scipy'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-10-93ad81cdfd38>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mmatplotlib\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpyplot\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mmatplotlib\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mimage\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mmpimg\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0msklearn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcluster\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mKMeans\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 7\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0msklearn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mutils\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mshuffle\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mtime\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mtime\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\users\\piyali\\python3\\lib\\site-packages\\sklearn\\__init__.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 55\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 56\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0m__check_build\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 57\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m\u001b[0mbase\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mclone\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 58\u001b[0m \u001b[0m__check_build\u001b[0m \u001b[1;31m# avoid flakes unused variable error\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 59\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\users\\piyali\\python3\\lib\\site-packages\\sklearn\\base.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 9\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mscipy\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0msparse\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 10\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m\u001b[0mexternals\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0msix\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m\u001b[0mutils\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfixes\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0msignature\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mImportError\u001b[0m: No module named 'scipy'"
]
}
],
"outputs": [],
"source": [
"# useful packages\n",
"import os\n",
Expand Down Expand Up @@ -136,11 +118,7 @@
},
{
"cell_type": "code",
<<<<<<< HEAD
"execution_count": 3,
=======
"execution_count": 28,
>>>>>>> origin/master
"metadata": {
"collapsed": false
},
Expand All @@ -149,7 +127,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"['columbia.jpg', 'leo_bb.png', 'mario.png']\n"
"['leo_bb.png', 'mario.png']\n"
]
}
],
Expand Down Expand Up @@ -179,8 +157,6 @@
"text": [
"Using image 0: path datasets/kmeans/imgs/leo_bb.png\n"
]
<<<<<<< HEAD
=======
},
{
"data": {
Expand All @@ -191,11 +167,10 @@
},
"metadata": {},
"output_type": "display_data"
>>>>>>> origin/master
}
],
"source": [
"img_path = os.path.join('datasets/kmeans/imgs/', imgs[1])\n",
"img_path = os.path.join('datasets/kmeans/imgs/', imgs[0])\n",
"print('Using image 0: path {}'.format(img_path))\n",
"\n",
"img = mpimg.imread(img_path)\n",
Expand All @@ -217,11 +192,7 @@
},
{
"cell_type": "code",
<<<<<<< HEAD
"execution_count": 6,
=======
"execution_count": 30,
>>>>>>> origin/master
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -253,27 +224,11 @@
},
{
"cell_type": "code",
<<<<<<< HEAD
"execution_count": 8,
=======
"execution_count": 31,
>>>>>>> origin/master
"metadata": {
"collapsed": false
"collapsed": true
},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'shuffle' is not defined",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-8-6ac900e80476>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mimg_reshaped\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreshape\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mimg\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mnum_pixels\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnum_channels\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mimg_sample\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mshuffle\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mimg_reshaped\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrandom_state\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mNameError\u001b[0m: name 'shuffle' is not defined"
]
}
],
"outputs": [],
"source": [
"img_reshaped = np.reshape(img, (num_pixels, num_channels))\n",
"img_sample = shuffle(img_reshaped, random_state=0)"
Expand Down Expand Up @@ -484,7 +439,7 @@
"We can also use **penalization approaches**, where we use different criterion such as AIC (Akaike Information Criterion) or BIC (Bayesian Information Criterion) to keep the value of k under control. \n",
"\n",
"#### I. (d) What if we can’t cluster the data?\n",
"In the tutorial above, we try to classify each of our points into one of K clusters. But sometimes, maybe you are clustering based on a feature that is not so exclusive. For example, people usually enjoy more than one genre of music, or food. It would be pretty difficult to form a clustering system such that a person can be a fan of ice-cream or a fan of tiramisu but not both. Hence when we need to \"share\" members of clusters, we are doing something called **probabilistic clustering** or **fuzzy clustering**. "
"* In the tutorial above, we try to classify each of our points into one of K clusters. But sometimes, maybe you are clustering based on a feature that is not so exclusive. For example, people usually enjoy more than one genre of music, or food. It would be pretty difficult to form a clustering system such that a person can be a fan of ice-cream or a fan of tiramisu but not both. Hence when we need to \"share\" members of clusters, we are doing something called **probabilistic clustering** or **fuzzy clustering**. "
]
},
{
Expand Down

0 comments on commit b9f526e

Please sign in to comment.