Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ajwije/6170ef7809a102cae800 to your computer and use it in GitHub Desktop.
Save ajwije/6170ef7809a102cae800 to your computer and use it in GitHub Desktop.
Comparing Python and R methods of plotting KMeans clustering within sum of squares against cluster size
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%load_ext rpy2.ipython"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Python"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"from sklearn.cluster import KMeans\n",
"from sklearn.datasets import load_iris\n",
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.text.Text at 0x29140f0>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEPCAYAAABP1MOPAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XucV3W97/HXm0EY5SqaIIqCXERKS01PpcGYBhambvfR\ntOPe7p2nXdsEdbct1Ej27kbXrfHYdtqpRSdxR1mmoFw0BrRSUlBRvOAoqaRkR0HUUGb4nD/WGubH\n8JvfrLn8bjPv5+OxHr91X5/fiOvzW9/vd32/igjMzKz36lPuAMzMrLycCMzMejknAjOzXs6JwMys\nl3MiMDPr5ZwIzMx6uaImAkmHS1qbM22VNFPSMEnLJT0laZmkoTnHXCFpg6QnJE0tZnxmZgYq1XsE\nkvoAm4DjgRnAXyLim5K+AOwbEbMkTQIWAMcBBwF3ARMiYmdJgjQz64VKWTR0CvB0RDwPnA7MT9fP\nB85M588Abo6IHRGxEXiaJHGYmVmRlDIRn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YRRFRsPlnRGxXMprcNZKuIakYf5hkdLP9c651C0lR1aMkN/Yn0/VH\nAt+StDM99jPp+v8ClkjaFBEnKxmc5ea0vgOSOoMNrcKpAf6vkvGiBVwbEa8Vit96LndDbWbWy7lo\nyMysl3MiMDPr5ZwIzMx6OScCM7NezonAzKyXcyIwM+vlnAjMzHo5JwIzs17u/wPsFxnIVGkhugAA\nAABJRU5ErkJggg==\n",
"text/plain": [
"<matplotlib.figure.Figure at 0xd872278>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"data = load_iris()['data']\n",
"results = []\n",
"for n_clusters in range(1, 16):\n",
" km = KMeans(n_clusters=n_clusters)\n",
" km.fit(data)\n",
" results.append({'n_clusters': n_clusters,\n",
" 'wss': km.inertia_})\n",
"pd.DataFrame(results).set_index('n_clusters').plot(marker='o')\n",
"plt.ylabel('Within groups sum of squares')\n",
"plt.xlabel('Number of Clusters')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## R"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAeAAAAHgCAMAAABKCk6nAAACiFBMVEUAAAAFBQUGBgYHBwcICAgJ\nCQkKCgoLCwsXFxceHh4iIiIkJCQlJSUtLS0yMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8\nPDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5P\nT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5gYGBhYWFiYmJj\nY2NkZGRlZWVmZmZnZ2doaGhpaWlqampra2tsbGxtbW1ubm5vb29wcHBxcXFycnJzc3N0dHR1dXV2\ndnZ3d3d4eHh5eXl6enp7e3t8fHx9fX1+fn5/f3+AgICBgYGCgoKEhISFhYWGhoaHh4eIiIiJ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vuuVbDcRP5YGzpdGzrjegvNf7+sBynsbgXLPU2OZGw52Ise8D\nBBf4l0LwbXnXLAQD1nvHoPOfvN5dtu/G0wHlxWjmwtBypV/WEjYJZu4gwX7pf75zikM0/1/spk7f\nQbd0125ZcKG/lj7Bfm+1A8qp3+hsGqsEF4sRgv2SYEFZafkmlPJPfsge7AdHb99hA8v5yvdCmMYq\nwfwkGrkHux4bYJYN3oPDzsGM9R7CB5dTnkfALHYJDprS4rbuIYL7zqVef0N50E8DW9Gl8sKj5w4p\nV/5lLWGX4ECUaD0PFVxuK/cedANKbePe/bK/H1wuXyg1mF1nYLkCWtEgX0Cw5UCw5UCw5UCw5UCw\n5UCw5UCw5UCw5UCw5UCw5UCw5UCw5UCw5UCw5UCw5UCw5UCw5UCw5fw/VYmChyXEe2gAAAAASUVO\nRK5CYII=\n"
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%R\n",
"data(iris)\n",
"mydata <- iris[1:4]\n",
"wss <- (nrow(mydata)-1)*sum(apply(mydata,2,var))\n",
"for (i in 2:15) wss[i] <- sum(kmeans(mydata, centers=i)$withinss)\n",
"plot(1:15, wss, type=\"b\", xlab=\"Number of Clusters\", ylab=\"Within groups sum of squares\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.8"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment