From b50ce25d4ad44e44cc8d765c6ee98a91ee5bc86b Mon Sep 17 00:00:00 2001 From: Anson Bridges Date: Mon, 11 Aug 2025 22:36:23 -0700 Subject: Clean junk "scratchpad" files and outdated CSVs --- Clustering2.0.ipynb | 313 ---------------------------------------------------- 1 file changed, 313 deletions(-) delete mode 100644 Clustering2.0.ipynb (limited to 'Clustering2.0.ipynb') diff --git a/Clustering2.0.ipynb b/Clustering2.0.ipynb deleted file mode 100644 index e312a2b..0000000 --- a/Clustering2.0.ipynb +++ /dev/null @@ -1,313 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "initial_id", - "metadata": { - "collapsed": true, - "ExecuteTime": { - "end_time": "2023-11-06T23:41:01.990393Z", - "start_time": "2023-11-06T23:41:01.040992Z" - } - }, - "outputs": [], - "source": [ - "import folium\n", - "import pandas as pd\n", - "import utils" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "outputs": [], - "source": [ - "# Load the data\n", - "ListA = pd.read_csv('List A.csv')\n", - "ListB = pd.read_csv('List B.csv')\n", - "ListC = pd.read_csv('List C.csv')\n", - "ListD = pd.read_csv('List D.csv')" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2023-11-06T23:41:02.000278Z", - "start_time": "2023-11-06T23:41:01.991024Z" - } - }, - "id": "bb6f57eef695cf76" - }, - { - "cell_type": "code", - "execution_count": 3, - "outputs": [], - "source": [ - "# Create two centroids, one in the North End and one in the Financial District\n", - "centroids = [[42.364506, -71.054733], [42.358894, -71.056742]]\n", - "\n", - "northeastern_coordinate = \"-71.09033,42.33976\"" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2023-11-06T23:41:02.003984Z", - "start_time": "2023-11-06T23:41:02.000633Z" - } - }, - "id": "fe8a5b9bc06cf2e0" - }, - { - "cell_type": "code", - "execution_count": 4, - "outputs": [ - { - "data": { - "text/plain": " name gps \\\n0 521 Commercial Street #525 42.3688272,-71.0553792 \n1 Acorn St 42.3576234,-71.0688746 \n2 Arlington's Great Meadows 42.4299758,-71.2038948 \n3 Arthur Fiedler Statue 42.3565057,-71.0754527 \n4 BU Beach 42.3511927,-71.1060828 \n.. ... ... \n28 The Clam Box 42.2763168,-71.0092883 \n29 The Partisans 42.3478375,-71.0404428 \n30 Union Oyster House 42.361288,-71.056908 \n31 Victoria's Diner 42.3270498,-71.0667744 \n32 Wollaston Beach 42.2806539,-71.0119933 \n\n googleUrl \\\n0 https://maps.google.com/maps?q=+%4042.3688272,... \n1 https://maps.google.com/maps?q=+%4042.3576234,... \n2 https://maps.google.com/maps?q=+%4042.4299758,... \n3 https://maps.google.com/maps?q=+%4042.3565057,... \n4 https://maps.google.com/maps?q=+%4042.3511927,... \n.. ... \n28 https://maps.google.com/maps?q=+%4042.2763168,... \n29 https://maps.google.com/maps?q=+%4042.3478375,... \n30 https://maps.google.com/maps?q=+%4042.361288,-... \n31 https://maps.google.com/maps?q=+%4042.3270498,... \n32 https://maps.google.com/maps?q=+%4042.2806539,... \n\n originalUrl info types \\\n0 https://www.google.com/maps/place/521+Commerci... NaN NaN \n1 https://www.google.com/maps/place/Acorn+St/dat... NaN NaN \n2 https://www.google.com/maps/place/Arlington's+... NaN NaN \n3 https://www.google.com/maps/place/Arthur+Fiedl... NaN NaN \n4 https://www.google.com/maps/place/BU+Beach/dat... NaN NaN \n.. ... ... ... \n28 https://www.google.com/maps/place/The+Clam+Box... NaN NaN \n29 https://www.google.com/maps/place/The+Partisan... NaN NaN \n30 https://www.google.com/maps/place/Union+Oyster... NaN NaN \n31 https://www.google.com/maps/place/Victoria's+D... NaN NaN \n32 https://www.google.com/maps/place/Wollaston+Be... NaN NaN \n\n address \\\n0 NaN \n1 NaN \n2 Minuteman Commuter Bikeway, Lexington, MA 0242... \n3 Charles River Esplanades, Boston, MA 02114, Un... \n4 270 Bay State Rd, Boston, MA 02215, United States \n.. ... \n28 789 Quincy Shore Dr, Quincy, MA 02170, United ... \n29 Boston, MA 02210, United States \n30 41 Union St, Boston, MA 02108, United States \n31 1024 Massachusetts Ave, Boston, MA 02118, Unit... \n32 Quincy, MA, United States \n\n description type \\\n0 NaN NaN \n1 NaN NaN \n2 183-acres of wet meadows & uplands with trails... Nature preserve \n3 NaN Sculpture \n4 A sloping, grassy plaza on the university grou... Park \n.. ... ... \n28 Classic beachfront joint with a rustic vibe di... Seafood restaurant \n29 NaN Sculpture \n30 Historic eatery serving chowder & other New En... Seafood restaurant \n31 Long-standing classic diner for breakfast & sa... Diner \n32 Historic 2.3-mi.-long beach with a paved prome... Beach \n\n phone website \\\n0 NaN NaN \n1 NaN NaN \n2 +1 781-863-5385 http://www.foagm.org/ \n3 +1 617-332-2433 http://helmicksculpture.com/portfolio/arthur-f... \n4 NaN https://www.bu.edu/today/2009/icons-among-us-t... \n.. ... ... \n28 +1 617-302-3474 http://www.clamboxquincy.com/ \n29 NaN https://www.bostonseaport.xyz/venue/the-partis... \n30 +1 617-227-2750 http://www.unionoysterhouse.com/?y_source=1_Mj... \n31 +1 617-442-5965 http://www.victoriasdiner.com/ \n32 NaN NaN \n\n ratingsAverage ratingsTotal plusCode list \n0 NaN NaN NaN A \n1 NaN NaN NaN A \n2 4.6 171.0 CQHW+XC Lexington, Massachusetts, USA A \n3 4.6 14.0 9W4F+JR Boston, Massachusetts, USA A \n4 4.5 133.0 9V2V+FH Boston, Massachusetts, USA A \n.. ... ... ... ... \n28 4.3 2145.0 7XGR+G7 Quincy, Massachusetts, USA C \n29 4.8 6.0 8XX5+4R Boston, Massachusetts, USA C \n30 4.3 8497.0 9W6V+G6 Boston, Massachusetts, USA C \n31 4.1 1797.0 8WGM+R7 Boston, Massachusetts, USA C \n32 4.4 171.0 NaN C \n\n[131 rows x 15 columns]", - "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
namegpsgoogleUrloriginalUrlinfotypesaddressdescriptiontypephonewebsiteratingsAverageratingsTotalplusCodelist
0521 Commercial Street #52542.3688272,-71.0553792https://maps.google.com/maps?q=+%4042.3688272,...https://www.google.com/maps/place/521+Commerci...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNA
1Acorn St42.3576234,-71.0688746https://maps.google.com/maps?q=+%4042.3576234,...https://www.google.com/maps/place/Acorn+St/dat...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNA
2Arlington's Great Meadows42.4299758,-71.2038948https://maps.google.com/maps?q=+%4042.4299758,...https://www.google.com/maps/place/Arlington's+...NaNNaNMinuteman Commuter Bikeway, Lexington, MA 0242...183-acres of wet meadows & uplands with trails...Nature preserve+1 781-863-5385http://www.foagm.org/4.6171.0CQHW+XC Lexington, Massachusetts, USAA
3Arthur Fiedler Statue42.3565057,-71.0754527https://maps.google.com/maps?q=+%4042.3565057,...https://www.google.com/maps/place/Arthur+Fiedl...NaNNaNCharles River Esplanades, Boston, MA 02114, Un...NaNSculpture+1 617-332-2433http://helmicksculpture.com/portfolio/arthur-f...4.614.09W4F+JR Boston, Massachusetts, USAA
4BU Beach42.3511927,-71.1060828https://maps.google.com/maps?q=+%4042.3511927,...https://www.google.com/maps/place/BU+Beach/dat...NaNNaN270 Bay State Rd, Boston, MA 02215, United StatesA sloping, grassy plaza on the university grou...ParkNaNhttps://www.bu.edu/today/2009/icons-among-us-t...4.5133.09V2V+FH Boston, Massachusetts, USAA
................................................
28The Clam Box42.2763168,-71.0092883https://maps.google.com/maps?q=+%4042.2763168,...https://www.google.com/maps/place/The+Clam+Box...NaNNaN789 Quincy Shore Dr, Quincy, MA 02170, United ...Classic beachfront joint with a rustic vibe di...Seafood restaurant+1 617-302-3474http://www.clamboxquincy.com/4.32145.07XGR+G7 Quincy, Massachusetts, USAC
29The Partisans42.3478375,-71.0404428https://maps.google.com/maps?q=+%4042.3478375,...https://www.google.com/maps/place/The+Partisan...NaNNaNBoston, MA 02210, United StatesNaNSculptureNaNhttps://www.bostonseaport.xyz/venue/the-partis...4.86.08XX5+4R Boston, Massachusetts, USAC
30Union Oyster House42.361288,-71.056908https://maps.google.com/maps?q=+%4042.361288,-...https://www.google.com/maps/place/Union+Oyster...NaNNaN41 Union St, Boston, MA 02108, United StatesHistoric eatery serving chowder & other New En...Seafood restaurant+1 617-227-2750http://www.unionoysterhouse.com/?y_source=1_Mj...4.38497.09W6V+G6 Boston, Massachusetts, USAC
31Victoria's Diner42.3270498,-71.0667744https://maps.google.com/maps?q=+%4042.3270498,...https://www.google.com/maps/place/Victoria's+D...NaNNaN1024 Massachusetts Ave, Boston, MA 02118, Unit...Long-standing classic diner for breakfast & sa...Diner+1 617-442-5965http://www.victoriasdiner.com/4.11797.08WGM+R7 Boston, Massachusetts, USAC
32Wollaston Beach42.2806539,-71.0119933https://maps.google.com/maps?q=+%4042.2806539,...https://www.google.com/maps/place/Wollaston+Be...NaNNaNQuincy, MA, United StatesHistoric 2.3-mi.-long beach with a paved prome...BeachNaNNaN4.4171.0NaNC
\n

131 rows × 15 columns

\n
" - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "# Combine the two lists and add a column to indicate the list\n", - "ListA['list'] = 'A'\n", - "ListB['list'] = 'B'\n", - "ListC['list'] = 'C'\n", - "ListD['list'] = 'D'\n", - "\n", - "TotalList = pd.concat([ListA, ListB, ListC])\n", - "display(TotalList)" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2023-11-06T23:41:02.012929Z", - "start_time": "2023-11-06T23:41:02.005863Z" - } - }, - "id": "dc434958d5e4a3a8" - }, - { - "cell_type": "code", - "execution_count": 5, - "outputs": [], - "source": [ - "# Remove all columns but name and gps\n", - "TotalList = TotalList[['name', 'gps', 'list']]" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2023-11-06T23:41:02.016943Z", - "start_time": "2023-11-06T23:41:02.013583Z" - } - }, - "id": "2873c16423fe3119" - }, - { - "cell_type": "code", - "execution_count": 6, - "outputs": [], - "source": [ - "# Convert the gps column to a list of lists for k-means\n", - "TotalList['gps'] = TotalList['gps'].apply(lambda x: x.strip('[]').split(','))\n", - "TotalList['gps'] = TotalList['gps'].apply(lambda x: [float(i) for i in x])" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2023-11-06T23:41:02.021308Z", - "start_time": "2023-11-06T23:41:02.016226Z" - } - }, - "id": "29f9155ef8d75fda" - }, - { - "cell_type": "code", - "execution_count": 7, - "outputs": [], - "source": [ - "# Create a new column with normalized gps coordinates and centroids\n", - "TotalList['normalized_gps'], norm_centroids = utils.normalize_gps(TotalList['gps'].values.tolist(), centroids)" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2023-11-06T23:41:02.021459Z", - "start_time": "2023-11-06T23:41:02.018449Z" - } - }, - "id": "5b985f1a6df84a6c" - }, - { - "cell_type": "code", - "execution_count": 8, - "outputs": [ - { - "data": { - "text/plain": " name gps list \\\n0 521 Commercial Street #525 [42.3688272, -71.0553792] A \n1 Acorn St [42.3576234, -71.0688746] A \n2 Arlington's Great Meadows [42.4299758, -71.2038948] A \n3 Arthur Fiedler Statue [42.3565057, -71.0754527] A \n4 BU Beach [42.3511927, -71.1060828] A \n.. ... ... ... \n28 The Clam Box [42.2763168, -71.0092883] C \n29 The Partisans [42.3478375, -71.0404428] C \n30 Union Oyster House [42.361288, -71.056908] C \n31 Victoria's Diner [42.3270498, -71.0667744] C \n32 Wollaston Beach [42.2806539, -71.0119933] C \n\n normalized_gps \n0 [0.7251058917247415, 0.8141430878559053] \n1 [0.6747391031099019, 0.778052752104061] \n2 [1.0, 0.41697235794883575] \n3 [0.6697144722136962, 0.7604611403245493] \n4 [0.6458298305822171, 0.6785480000609988] \n.. ... \n28 [0.30922451563130937, 0.9374025730216268] \n29 [0.6307464973238023, 0.8540870458656248] \n30 [0.6912133469876947, 0.8100546647415456] \n31 [0.5372951958288665, 0.7836692527743693] \n32 [0.32872198960456106, 0.9301686741961767] \n\n[131 rows x 4 columns]", - "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
namegpslistnormalized_gps
0521 Commercial Street #525[42.3688272, -71.0553792]A[0.7251058917247415, 0.8141430878559053]
1Acorn St[42.3576234, -71.0688746]A[0.6747391031099019, 0.778052752104061]
2Arlington's Great Meadows[42.4299758, -71.2038948]A[1.0, 0.41697235794883575]
3Arthur Fiedler Statue[42.3565057, -71.0754527]A[0.6697144722136962, 0.7604611403245493]
4BU Beach[42.3511927, -71.1060828]A[0.6458298305822171, 0.6785480000609988]
...............
28The Clam Box[42.2763168, -71.0092883]C[0.30922451563130937, 0.9374025730216268]
29The Partisans[42.3478375, -71.0404428]C[0.6307464973238023, 0.8540870458656248]
30Union Oyster House[42.361288, -71.056908]C[0.6912133469876947, 0.8100546647415456]
31Victoria's Diner[42.3270498, -71.0667744]C[0.5372951958288665, 0.7836692527743693]
32Wollaston Beach[42.2806539, -71.0119933]C[0.32872198960456106, 0.9301686741961767]
\n

131 rows × 4 columns

\n
" - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "display(TotalList)" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2023-11-06T23:41:02.028731Z", - "start_time": "2023-11-06T23:41:02.023494Z" - } - }, - "id": "a03a7c5dacebddd0" - }, - { - "cell_type": "markdown", - "source": [ - "# Cluster and Minimize" - ], - "metadata": { - "collapsed": false - }, - "id": "ee3ab1c81ea71b0" - }, - { - "cell_type": "code", - "execution_count": 9, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/garrinshieh/anaconda3/lib/python3.11/site-packages/sklearn/cluster/_kmeans.py:1412: FutureWarning: The default value of `n_init` will change from 10 to 'auto' in 1.4. Set the value of `n_init` explicitly to suppress the warning\n", - " super()._check_params_vs_input(X, default_n_init=10)\n", - "/Users/garrinshieh/anaconda3/lib/python3.11/site-packages/sklearn/cluster/_kmeans.py:1412: RuntimeWarning: Explicit initial center position passed: performing only one init in KMeans instead of n_init=10.\n", - " super()._check_params_vs_input(X, default_n_init=10)\n" - ] - } - ], - "source": [ - "# Cluster and minimize the data\n", - "df, route_1_coordinates, route_2_coordinates = utils.cluster_and_minimize(TotalList, centroids, norm_centroids,\n", - " northeastern_coordinate, 0.5)" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2023-11-06T23:41:28.583623Z", - "start_time": "2023-11-06T23:41:02.026243Z" - } - }, - "id": "a1a3e446594e8c20" - }, - { - "cell_type": "markdown", - "source": [ - "# Map" - ], - "metadata": { - "collapsed": false - }, - "id": "dc35d41885a19079" - }, - { - "cell_type": "code", - "execution_count": 11, - "outputs": [ - { - "data": { - "text/plain": "", - "text/html": "
Make this Notebook Trusted to load map: File -> Trust Notebook
" - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Create a new map with the new coordinates\n", - "m = folium.Map(location=[42.3601, -71.0589], zoom_start=12)\n", - "\n", - "# Plot the centroids on the map\n", - "for i in range(len(centroids)):\n", - " folium.Marker(centroids[i], popup='Centroid ' + str(i), icon=folium.Icon(color='black')).add_to(m)\n", - "\n", - "# Add the points to the map with different colors for each cluster\n", - "for i, row in df.iterrows():\n", - " if row['cluster'] == 0:\n", - " folium.Marker([row['gps'][0], row['gps'][1]], popup=row['name'], icon=folium.Icon(color='red')).add_to(m)\n", - " elif row['cluster'] == 1:\n", - " folium.Marker([row['gps'][0], row['gps'][1]], popup=row['name'], icon=folium.Icon(color='blue')).add_to(m)\n", - " elif row['cluster'] == 2:\n", - " folium.Marker([row['gps'][0], row['gps'][1]], popup=row['name'], icon=folium.Icon(color='green')).add_to(m)\n", - " elif row['cluster'] == 3:\n", - " folium.Marker([row['gps'][0], row['gps'][1]], popup=row['name'], icon=folium.Icon(color='purple')).add_to(m)\n", - " elif row['cluster'] == 4:\n", - " folium.Marker([row['gps'][0], row['gps'][1]], popup=row['name'], icon=folium.Icon(color='orange')).add_to(m)\n", - " elif row['cluster'] == 5:\n", - " folium.Marker([row['gps'][0], row['gps'][1]], popup=row['name'], icon=folium.Icon(color='darkred')).add_to(m)\n", - " elif row['cluster'] == 6:\n", - " folium.Marker([row['gps'][0], row['gps'][1]], popup=row['name'], icon=folium.Icon(color='lightred')).add_to(m)\n", - " elif row['cluster'] == 7:\n", - " folium.Marker([row['gps'][0], row['gps'][1]], popup=row['name'], icon=folium.Icon(color='beige')).add_to(m)\n", - " elif row['cluster'] == 8:\n", - " folium.Marker([row['gps'][0], row['gps'][1]], popup=row['name'], icon=folium.Icon(color='darkblue')).add_to(m)\n", - " elif row['cluster'] == 9:\n", - " folium.Marker([row['gps'][0], row['gps'][1]], popup=row['name'], icon=folium.Icon(color='lightblue')).add_to(m)\n", - " elif row['cluster'] == 10:\n", - " folium.Marker([row['gps'][0], row['gps'][1]], popup=row['name'], icon=folium.Icon(color='cadet')).add_to(m)\n", - "\n", - "# Display the map\n", - "m" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2023-11-06T23:41:34.488607Z", - "start_time": "2023-11-06T23:41:34.368207Z" - } - }, - "id": "de9c2f7b892b1bee" - }, - { - "cell_type": "code", - "execution_count": 10, - "outputs": [], - "source": [], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2023-11-06T23:41:28.671570Z", - "start_time": "2023-11-06T23:41:28.667750Z" - } - }, - "id": "b50ee3d4d6e09be9" - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "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.6" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} -- cgit v1.2.3