Created
June 25, 2021 13:43
-
-
Save JonathanReeve/64ad4a25e37528e25fd6ee2af5aa0d18 to your computer and use it in GitHub Desktop.
05-nyu-pit-ml.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "05-nyu-pit-ml.ipynb", | |
"provenance": [], | |
"authorship_tag": "ABX9TyOhXIXoNtC6QsxXgQdb3c/I", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/JonathanReeve/64ad4a25e37528e25fd6ee2af5aa0d18/05-nyu-pit-ml.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "RN2AGSNgSTa0" | |
}, | |
"source": [ | |
"" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "EDTMx8jUTFzU" | |
}, | |
"source": [ | |
"- Machine learning\n", | |
"- Artificial intelligence (neural net)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "D_s00s1DTY46" | |
}, | |
"source": [ | |
"import nltk\n", | |
"import spacy\n", | |
"from nltk.corpus import gutenberg\n", | |
"import pandas as pd\n", | |
"from sklearn.decomposition import PCA\n", | |
"from plotly import express as px\n", | |
"from sklearn.cluster import KMeans" | |
], | |
"execution_count": 29, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "Tj58z97xTy1X", | |
"outputId": "5dac1931-216e-406d-cb26-de451403d3e7" | |
}, | |
"source": [ | |
"nltk.download('gutenberg')" | |
], | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"[nltk_data] Downloading package gutenberg to /root/nltk_data...\n", | |
"[nltk_data] Unzipping corpora/gutenberg.zip.\n" | |
], | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 2 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "BAj9gn-rT1w_", | |
"outputId": "ef602191-8a20-459f-b206-82e3164c04c0" | |
}, | |
"source": [ | |
"spacy.cli.download('en_core_web_lg')" | |
], | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\u001b[38;5;2m✔ Download and installation successful\u001b[0m\n", | |
"You can now load the model via spacy.load('en_core_web_lg')\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "LcL3lVpHT5FY" | |
}, | |
"source": [ | |
"nlp = spacy.load('en_core_web_lg')" | |
], | |
"execution_count": 4, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "IvNt0WDMT9l1" | |
}, | |
"source": [ | |
"emmaRaw = gutenberg.raw(gutenberg.fileids()[0])" | |
], | |
"execution_count": 5, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "qhIB7wV9VlWH" | |
}, | |
"source": [ | |
"emmaDoc = nlp(emmaRaw)" | |
], | |
"execution_count": 7, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "L8vTfUXRVmYw" | |
}, | |
"source": [ | |
"emmaNouns = [w for w in emmaDoc if w.pos_ == \"NOUN\"][:100]" | |
], | |
"execution_count": 8, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "8JfHBRZpYiHG" | |
}, | |
"source": [ | |
"list(emmaDoc.noun_chunks)[:20]" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "IT6ozzJTVzdX" | |
}, | |
"source": [ | |
"emmaVecs = [w.vector for w in emmaNouns]" | |
], | |
"execution_count": 10, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "vuOLn03YWnmU" | |
}, | |
"source": [ | |
"emmaNouns" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "tuDrTrLHX0qB" | |
}, | |
"source": [ | |
"labels = [str(w) for w in emmaNouns]" | |
], | |
"execution_count": 23, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "4VKWw0QyV0iQ" | |
}, | |
"source": [ | |
"df = pd.DataFrame(emmaVecs)" | |
], | |
"execution_count": 14, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "vKNXm26LWD70" | |
}, | |
"source": [ | |
"pca = PCA(n_components=3)" | |
], | |
"execution_count": 18, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "NgL9-0shWNvm" | |
}, | |
"source": [ | |
"pcaOut = pca.fit_transform(df)\n", | |
"pcaDf = pd.DataFrame(pcaOut)" | |
], | |
"execution_count": 21, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 542 | |
}, | |
"id": "EKvUHo5UXX67", | |
"outputId": "bf1ff5f7-8d3a-4d9e-88d6-0e9c3b2c710e" | |
}, | |
"source": [ | |
"px.scatter_3d(pcaDf, x=0, y=1, z=2, text=labels)" | |
], | |
"execution_count": 24, | |
"outputs": [ | |
{ | |
"output_type": "display_data", | |
"data": { | |
"text/html": [ | |
"<html>\n", | |
"<head><meta charset=\"utf-8\" /></head>\n", | |
"<body>\n", | |
" <div>\n", | |
" <script src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG\"></script><script type=\"text/javascript\">if (window.MathJax) {MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script>\n", | |
" <script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>\n", | |
" <script src=\"https://cdn.plot.ly/plotly-latest.min.js\"></script> \n", | |
" <div id=\"44bf3f34-48ce-4376-a155-f5d17aadb8a5\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div>\n", | |
" <script type=\"text/javascript\">\n", | |
" \n", | |
" window.PLOTLYENV=window.PLOTLYENV || {};\n", | |
" \n", | |
" if (document.getElementById(\"44bf3f34-48ce-4376-a155-f5d17aadb8a5\")) {\n", | |
" Plotly.newPlot(\n", | |
" '44bf3f34-48ce-4376-a155-f5d17aadb8a5',\n", | |
" [{\"hoverlabel\": {\"namelength\": 0}, \"hovertemplate\": \"0=%{x}<br>1=%{y}<br>2=%{z}<br>text=%{text}\", \"legendgroup\": \"\", \"marker\": {\"color\": \"#636efa\", \"symbol\": \"circle\"}, \"mode\": \"markers+text\", \"name\": \"\", \"scene\": \"scene\", \"showlegend\": false, \"text\": [\"VOLUME\", \"CHAPTER\", \"home\", \"disposition\", \"blessings\", \"existence\", \"years\", \"world\", \"daughters\", \"consequence\", \"sister\", \"marriage\", \"mistress\", \"house\", \"period\", \"mother\", \"remembrance\", \"caresses\", \"place\", \"woman\", \"governess\", \"mother\", \"affection\", \"years\", \"family\", \"governess\", \"friend\", \"daughters\", \"_\", \"_\", \"intimacy\", \"sisters\", \"office\", \"governess\", \"mildness\", \"temper\", \"restraint\", \"shadow\", \"authority\", \"friend\", \"friend\", \"judgment\", \"evils\", \"situation\", \"power\", \"way\", \"disposition\", \"disadvantages\", \"alloy\", \"enjoyments\", \"danger\", \"present\", \"means\", \"rank\", \"misfortunes\", \"Sorrow\", \"sorrow\", \"shape\", \"loss\", \"grief\", \"wedding\", \"day\", \"friend\", \"thought\", \"continuance\", \"wedding\", \"bride\", \"people\", \"father\", \"prospect\", \"evening\", \"father\", \"dinner\", \"event\", \"promise\", \"happiness\", \"friend\", \"man\", \"character\", \"fortune\", \"age\", \"manners\", \"satisfaction\", \"self\", \"friendship\", \"match\", \"morning\", \"work\", \"want\", \"hour\", \"day\", \"kindness\", \"kindness\", \"affection\", \"years\", \"years\", \"powers\", \"health\", \"illnesses\", \"childhood\"], \"type\": \"scatter3d\", \"x\": [0.4485541237878793, -0.24847808766869472, -1.8425193789396803, 2.770894868671479, 1.4890789942225255, 1.0832093459863765, -1.8138581817149977, -0.533222243257348, -1.6396483339145305, 1.8740959029509894, -2.3461055788836043, -1.0774899747008544, 0.068103521037855, -1.9829790847459015, -0.5364469902408102, -2.08645369376346, 1.1677187877614275, 2.388796410683049, -0.9476770516698373, -1.78199049409224, 1.49139421681328, -2.08645369376346, 2.1610107373391334, -1.8138581817149986, -1.9619178763851755, 1.491394216813281, -2.3015667648509903, -1.639648333914532, -0.055026755426982134, -0.05502675542698236, 1.8998776064760317, -1.6010712144030623, -1.362470874864566, 1.491394216813281, 4.134056474448503, 2.036352229374756, 2.719703812477164, 0.3265707636138679, 1.369837359332965, -2.3015667648509903, -2.3015667648509903, 2.105337469550644, 2.6698558201491975, 0.07162528831097106, 0.808785286076019, -0.6731473390950194, 2.7708948686714807, 1.546285592563519, 0.7910385806261023, 3.81279655079264, 1.0811100531115325, -0.2688857776398207, 0.2643244612320651, 0.6381530496485328, 3.1580003320435055, 2.6095414881036247, 2.6095414881036247, -0.08307728461243838, 0.36435097957859364, 1.393337539806271, -3.3162195222935376, -1.8310006996426031, -2.3015667648509903, -1.0033866956075623, 2.625490045000544, -3.316219522293538, -1.7512733842792367, -0.922840403704893, -1.8443373838035673, 0.26019279262787054, -1.9201533914795579, -1.8443373838035677, -2.630582803066747, -1.569059314950446, 0.28622673431249884, 1.5194786979385693, -2.3015667648509903, -1.0008301828654544, 0.1504245758313926, 0.3688901490862279, -1.31803223840521, 2.010350001022495, 1.3698926667109825, 0.35128023357031557, 0.3307955984242085, -1.084727713740601, -1.95213481008195, -1.0487956755668406, -1.1785414193149415, -1.559566741301203, -1.8310006996426036, 2.665527857050765, 2.665527857050765, 2.161010737339134, -1.8138581817149977, -1.8138581817149977, 1.6454040884397918, -0.04175867912891995, 1.3900258026662653, -0.36973824054709], \"y\": [-2.7412362881209735, -1.4661658234149715, -0.8787311004871656, -0.5750891538192071, 0.9100986179559807, -1.4678818204784223, -1.5656152993995562, -1.4971260390524603, 2.9620626051317624, -1.3603352598224119, 2.9278215273990194, 1.186049757713111, 2.8078577384046466, -0.2107407012466519, -2.8704415896725988, 2.76984889345182, 0.723911554826222, 2.0141663381581347, -1.68669581744366, 1.3321349438895604, 3.646869131815349, 2.7698488934518206, 1.758001839989489, -1.5656152993995567, 1.015735238717625, 3.6468691318153494, 1.6946538208073674, 2.9620626051317633, -0.9905743512578753, -0.9905743512578751, 0.821145180426155, 2.841075736715148, -1.5376473820259362, 3.6468691318153494, 0.9280862218052724, 0.8013172782410299, -0.6798340169454561, -0.7610819333578698, -1.786068301530982, 1.6946538208073674, 1.6946538208073674, -1.2172917022290624, -0.2580416344863495, -1.348079624208958, -2.299474616276322, -1.3825062012130236, -0.575089153819207, -1.615088839986715, -1.9483269124118099, 0.8754856325892044, -0.9969409524447493, -1.6342549575785528, -1.9616563941358394, -1.7079764217151758, 1.0156359381391196, 1.487289499470324, 1.4872894994703234, -1.763833181751875, -2.108118367874211, 1.148286724317861, 0.503493176864711, -1.4350011667067097, 1.6946538208073674, -0.6644237710908145, -1.1221047448311225, 0.5034931768647111, 2.268719885949365, -1.5824626471793513, 2.480476338292455, -1.2949437649586741, -0.5794951592961041, 2.480476338292455, 0.05758121701906804, -2.2869591087612613, -0.699205447254328, 0.4280180405611514, 1.6946538208073674, 0.08798233959666028, -0.051255747365954715, 0.21180938149367506, -0.6920557593636526, 0.8736604156999697, -1.2997861687325594, -0.9040999173210609, 1.4980374286526643, -1.9520857965733514, -0.5846412173037269, -1.709894092577369, -1.2700305935023222, -1.8168296898981013, -1.4350011667067097, 1.7267027586328547, 1.7267027586328552, 1.7580018399894892, -1.5656152993995565, -1.5656152993995565, -1.4237164807938711, -2.157696934175294, -1.0589005455532503, 1.035710146189828], \"z\": [1.4751889439544774, 0.3482473978449201, 0.2939391832954692, 0.4754140216426554, -3.0178771214029583, -0.027556965652948868, 0.732760717386927, -0.19237659380270025, 0.27039973704914205, 0.3197868971710197, 0.4955880062852869, -0.6402234580492336, 2.263960159436547, 0.5617667905772061, 0.8891406458627541, 0.1738753081017389, -2.31670103521307, 0.19673968068854272, -0.08788468044070155, 0.31054283256297727, 4.798463324928295, 0.17387530810173882, -1.630956302628929, 0.7327607173869274, -0.5569596502952936, 4.798463324928297, -0.3654922001336372, 0.27039973704914233, 0.9424358816981472, 0.9424358816981472, -1.5087176623440235, 0.07255439529896754, 1.16612518474477, 4.798463324928297, 0.8857754982420597, 0.5212087625943714, 0.7335410825937724, 0.20442145883683535, 0.916054401485335, -0.3654922001336371, -0.3654922001336371, -0.06739576041551895, -0.07385144707530326, 0.369434368389955, 0.5078924475509099, -0.19372686555278543, 0.4754140216426547, 0.8298241980420946, 2.3612517158506825, -0.05922639503811567, -0.12239114380093928, 0.35157782531540493, 0.034077879979005174, 1.192716449831028, -0.19275568255460315, -2.6476714419121934, -2.6476714419121925, 0.5327803695512974, -0.43886520535218204, -2.1469005336437164, -1.6223557029086326, -0.8118281358834141, -0.365492200133637, -0.09650767582628046, 0.20459482445454244, -1.6223557029086326, -0.5949246002516537, -0.750494884163108, 0.2570554457379362, 0.6229322200042634, -0.8701064791929668, 0.2570554457379364, -0.9771221765108807, -0.8844414801686578, -0.9554039474447655, -2.7025341487933368, -0.3654922001336371, -0.21299960451498465, 0.8882640245895267, -0.08039364263112528, 1.0802930975743616, 0.6378365999407948, -0.70558206490376, -0.44827035391315984, -2.046327432926013, 0.4132102790208657, -0.7245816595126443, 0.3971145755036143, -0.13600855666040917, 0.04690748547246332, -0.8118281358834143, -2.560777808123494, -2.5607778081234933, -1.6309563026289289, 0.7327607173869276, 0.7327607173869276, 0.9642380525466143, -0.10916025575343724, -0.058114597821378025, -0.2832978226804047]}],\n", | |
" {\"legend\": {\"tracegroupgap\": 0}, \"margin\": {\"t\": 60}, \"scene\": {\"domain\": {\"x\": [0.0, 1.0], \"y\": [0.0, 1.0]}, \"xaxis\": {\"title\": {\"text\": \"0\"}}, \"yaxis\": {\"title\": {\"text\": \"1\"}}, \"zaxis\": {\"title\": {\"text\": \"2\"}}}, \"template\": {\"data\": {\"bar\": [{\"error_x\": {\"color\": \"#2a3f5f\"}, \"error_y\": {\"color\": \"#2a3f5f\"}, \"marker\": {\"line\": {\"color\": \"#E5ECF6\", \"width\": 0.5}}, \"type\": \"bar\"}], \"barpolar\": [{\"marker\": {\"line\": {\"color\": \"#E5ECF6\", \"width\": 0.5}}, \"type\": \"barpolar\"}], \"carpet\": [{\"aaxis\": {\"endlinecolor\": \"#2a3f5f\", \"gridcolor\": \"white\", \"linecolor\": \"white\", \"minorgridcolor\": \"white\", \"startlinecolor\": \"#2a3f5f\"}, \"baxis\": {\"endlinecolor\": \"#2a3f5f\", \"gridcolor\": \"white\", \"linecolor\": \"white\", \"minorgridcolor\": \"white\", \"startlinecolor\": \"#2a3f5f\"}, \"type\": \"carpet\"}], \"choropleth\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"type\": \"choropleth\"}], \"contour\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"colorscale\": [[0.0, \"#0d0887\"], [0.1111111111111111, \"#46039f\"], [0.2222222222222222, \"#7201a8\"], [0.3333333333333333, \"#9c179e\"], [0.4444444444444444, \"#bd3786\"], [0.5555555555555556, \"#d8576b\"], [0.6666666666666666, \"#ed7953\"], [0.7777777777777778, \"#fb9f3a\"], [0.8888888888888888, \"#fdca26\"], [1.0, \"#f0f921\"]], \"type\": \"contour\"}], \"contourcarpet\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"type\": \"contourcarpet\"}], \"heatmap\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"colorscale\": [[0.0, \"#0d0887\"], [0.1111111111111111, \"#46039f\"], [0.2222222222222222, \"#7201a8\"], [0.3333333333333333, \"#9c179e\"], [0.4444444444444444, \"#bd3786\"], [0.5555555555555556, \"#d8576b\"], [0.6666666666666666, \"#ed7953\"], [0.7777777777777778, \"#fb9f3a\"], [0.8888888888888888, \"#fdca26\"], [1.0, \"#f0f921\"]], \"type\": \"heatmap\"}], \"heatmapgl\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"colorscale\": [[0.0, \"#0d0887\"], [0.1111111111111111, \"#46039f\"], [0.2222222222222222, \"#7201a8\"], [0.3333333333333333, \"#9c179e\"], [0.4444444444444444, \"#bd3786\"], [0.5555555555555556, \"#d8576b\"], [0.6666666666666666, \"#ed7953\"], [0.7777777777777778, \"#fb9f3a\"], [0.8888888888888888, \"#fdca26\"], [1.0, \"#f0f921\"]], \"type\": \"heatmapgl\"}], \"histogram\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"histogram\"}], \"histogram2d\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"colorscale\": [[0.0, \"#0d0887\"], [0.1111111111111111, \"#46039f\"], [0.2222222222222222, \"#7201a8\"], [0.3333333333333333, \"#9c179e\"], [0.4444444444444444, \"#bd3786\"], [0.5555555555555556, \"#d8576b\"], [0.6666666666666666, \"#ed7953\"], [0.7777777777777778, \"#fb9f3a\"], [0.8888888888888888, \"#fdca26\"], [1.0, \"#f0f921\"]], \"type\": \"histogram2d\"}], \"histogram2dcontour\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"colorscale\": [[0.0, \"#0d0887\"], [0.1111111111111111, \"#46039f\"], [0.2222222222222222, \"#7201a8\"], [0.3333333333333333, \"#9c179e\"], [0.4444444444444444, \"#bd3786\"], [0.5555555555555556, \"#d8576b\"], [0.6666666666666666, \"#ed7953\"], [0.7777777777777778, \"#fb9f3a\"], [0.8888888888888888, \"#fdca26\"], [1.0, \"#f0f921\"]], \"type\": \"histogram2dcontour\"}], \"mesh3d\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"type\": \"mesh3d\"}], \"parcoords\": [{\"line\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"parcoords\"}], \"pie\": [{\"automargin\": true, \"type\": \"pie\"}], \"scatter\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scatter\"}], \"scatter3d\": [{\"line\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scatter3d\"}], \"scattercarpet\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scattercarpet\"}], \"scattergeo\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scattergeo\"}], \"scattergl\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scattergl\"}], \"scattermapbox\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scattermapbox\"}], \"scatterpolar\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scatterpolar\"}], \"scatterpolargl\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scatterpolargl\"}], \"scatterternary\": [{\"marker\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"type\": \"scatterternary\"}], \"surface\": [{\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}, \"colorscale\": [[0.0, \"#0d0887\"], [0.1111111111111111, \"#46039f\"], [0.2222222222222222, \"#7201a8\"], [0.3333333333333333, \"#9c179e\"], [0.4444444444444444, \"#bd3786\"], [0.5555555555555556, \"#d8576b\"], [0.6666666666666666, \"#ed7953\"], [0.7777777777777778, \"#fb9f3a\"], [0.8888888888888888, \"#fdca26\"], [1.0, \"#f0f921\"]], \"type\": \"surface\"}], \"table\": [{\"cells\": {\"fill\": {\"color\": \"#EBF0F8\"}, \"line\": {\"color\": \"white\"}}, \"header\": {\"fill\": {\"color\": \"#C8D4E3\"}, \"line\": {\"color\": \"white\"}}, \"type\": \"table\"}]}, \"layout\": {\"annotationdefaults\": {\"arrowcolor\": \"#2a3f5f\", \"arrowhead\": 0, \"arrowwidth\": 1}, \"coloraxis\": {\"colorbar\": {\"outlinewidth\": 0, \"ticks\": \"\"}}, \"colorscale\": {\"diverging\": [[0, \"#8e0152\"], [0.1, \"#c51b7d\"], [0.2, \"#de77ae\"], [0.3, \"#f1b6da\"], [0.4, \"#fde0ef\"], [0.5, \"#f7f7f7\"], [0.6, \"#e6f5d0\"], [0.7, \"#b8e186\"], [0.8, \"#7fbc41\"], [0.9, \"#4d9221\"], [1, \"#276419\"]], \"sequential\": [[0.0, \"#0d0887\"], [0.1111111111111111, \"#46039f\"], [0.2222222222222222, \"#7201a8\"], [0.3333333333333333, \"#9c179e\"], [0.4444444444444444, \"#bd3786\"], [0.5555555555555556, \"#d8576b\"], [0.6666666666666666, \"#ed7953\"], [0.7777777777777778, \"#fb9f3a\"], [0.8888888888888888, \"#fdca26\"], [1.0, \"#f0f921\"]], \"sequentialminus\": [[0.0, \"#0d0887\"], [0.1111111111111111, \"#46039f\"], [0.2222222222222222, \"#7201a8\"], [0.3333333333333333, \"#9c179e\"], [0.4444444444444444, \"#bd3786\"], [0.5555555555555556, \"#d8576b\"], [0.6666666666666666, \"#ed7953\"], [0.7777777777777778, \"#fb9f3a\"], [0.8888888888888888, \"#fdca26\"], [1.0, \"#f0f921\"]]}, \"colorway\": [\"#636efa\", \"#EF553B\", \"#00cc96\", \"#ab63fa\", \"#FFA15A\", \"#19d3f3\", \"#FF6692\", \"#B6E880\", \"#FF97FF\", \"#FECB52\"], \"font\": {\"color\": \"#2a3f5f\"}, \"geo\": {\"bgcolor\": \"white\", \"lakecolor\": \"white\", \"landcolor\": \"#E5ECF6\", \"showlakes\": true, \"showland\": true, \"subunitcolor\": \"white\"}, \"hoverlabel\": {\"align\": \"left\"}, \"hovermode\": \"closest\", \"mapbox\": {\"style\": \"light\"}, \"paper_bgcolor\": \"white\", \"plot_bgcolor\": \"#E5ECF6\", \"polar\": {\"angularaxis\": {\"gridcolor\": \"white\", \"linecolor\": \"white\", \"ticks\": \"\"}, \"bgcolor\": \"#E5ECF6\", \"radialaxis\": {\"gridcolor\": \"white\", \"linecolor\": \"white\", \"ticks\": \"\"}}, \"scene\": {\"xaxis\": {\"backgroundcolor\": \"#E5ECF6\", \"gridcolor\": \"white\", \"gridwidth\": 2, \"linecolor\": \"white\", \"showbackground\": true, \"ticks\": \"\", \"zerolinecolor\": \"white\"}, \"yaxis\": {\"backgroundcolor\": \"#E5ECF6\", \"gridcolor\": \"white\", \"gridwidth\": 2, \"linecolor\": \"white\", \"showbackground\": true, \"ticks\": \"\", \"zerolinecolor\": \"white\"}, \"zaxis\": {\"backgroundcolor\": \"#E5ECF6\", \"gridcolor\": \"white\", \"gridwidth\": 2, \"linecolor\": \"white\", \"showbackground\": true, \"ticks\": \"\", \"zerolinecolor\": \"white\"}}, \"shapedefaults\": {\"line\": {\"color\": \"#2a3f5f\"}}, \"ternary\": {\"aaxis\": {\"gridcolor\": \"white\", \"linecolor\": \"white\", \"ticks\": \"\"}, \"baxis\": {\"gridcolor\": \"white\", \"linecolor\": \"white\", \"ticks\": \"\"}, \"bgcolor\": \"#E5ECF6\", \"caxis\": {\"gridcolor\": \"white\", \"linecolor\": \"white\", \"ticks\": \"\"}}, \"title\": {\"x\": 0.05}, \"xaxis\": {\"automargin\": true, \"gridcolor\": \"white\", \"linecolor\": \"white\", \"ticks\": \"\", \"title\": {\"standoff\": 15}, \"zerolinecolor\": \"white\", \"zerolinewidth\": 2}, \"yaxis\": {\"automargin\": true, \"gridcolor\": \"white\", \"linecolor\": \"white\", \"ticks\": \"\", \"title\": {\"standoff\": 15}, \"zerolinecolor\": \"white\", \"zerolinewidth\": 2}}}},\n", | |
" {\"responsive\": true}\n", | |
" ).then(function(){\n", | |
" \n", | |
"var gd = document.getElementById('44bf3f34-48ce-4376-a155-f5d17aadb8a5');\n", | |
"var x = new MutationObserver(function (mutations, observer) {{\n", | |
" var display = window.getComputedStyle(gd).display;\n", | |
" if (!display || display === 'none') {{\n", | |
" console.log([gd, 'removed!']);\n", | |
" Plotly.purge(gd);\n", | |
" observer.disconnect();\n", | |
" }}\n", | |
"}});\n", | |
"\n", | |
"// Listen for the removal of the full notebook cells\n", | |
"var notebookContainer = gd.closest('#notebook-container');\n", | |
"if (notebookContainer) {{\n", | |
" x.observe(notebookContainer, {childList: true});\n", | |
"}}\n", | |
"\n", | |
"// Listen for the clearing of the current output cell\n", | |
"var outputEl = gd.closest('.output');\n", | |
"if (outputEl) {{\n", | |
" x.observe(outputEl, {childList: true});\n", | |
"}}\n", | |
"\n", | |
" })\n", | |
" };\n", | |
" \n", | |
" </script>\n", | |
" </div>\n", | |
"</body>\n", | |
"</html>" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "ggKSil4yXtie" | |
}, | |
"source": [ | |
"kmeans = KMeans(n_clusters=4)\n", | |
"kmeansOut = kmeans.fit_transform(pcaDf)" | |
], | |
"execution_count": 30, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "_Gt7sZdAZHAf", | |
"outputId": "00b876cb-a315-4a3d-f5f6-ca73575624ae" | |
}, | |
"source": [ | |
"kmeans.cluster_centers_" | |
], | |
"execution_count": 31, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"array([[ 1.13557154, 3.43711628, 4.16483753],\n", | |
" [-0.34541061, -1.37005317, 0.25224662],\n", | |
" [-2.03815816, 1.83665998, -0.27825495],\n", | |
" [ 2.32812401, 0.7314328 , -0.98669058]])" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 31 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "JwyyZi2vZK_8" | |
}, | |
"source": [ | |
"" | |
], | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment