US states Internet connection speed similarity (30.06.2014)

from sklearn.metrics.pairwise import cosine_similarity from sklearn.preprocessing import MinMaxScaler import numpy as np broadband_internet_types = { 'home': """ Alabama,2.32617,5.66401,12.88504,0.388,1.00098,1.95996,8251 Alaska,0.97168,2.59594,4.98828,0.25879,0.4668,0.66797,1485 Arizona,3.08301,7.45703,16.51736,0.71582,1.876,4.482,26197 Arkansas,1.45313,4.82785,10.43457,0.41016,0.675,2.62109,4373 California,2.3584,6.13222,16.84863,0.437,0.9541,2.88965,110669 Colorado,2.10043,6.61572,16.43848,0.70703,1.46729,3.89258,17652 Connecticut,2.47971,6.28125,14.60938,0.436,1.76483,3.212,10518 Delaware,6.00488,14.95423,20.55371,1.73438,3.99854,5.459,1934 District of Columbia,2.29297,6.32465,17.15137,0.65137,1.44825,3.92383,3744 Florida,2.85059,8.04151,15.5,0.47949,1.4043,3.10059,46340 Georgia,2.5498,5.94336,16.64844,0.392,1.03418,3.24219,20695 Hawaii,2.21191,5.47007,10.39554,0.60352,0.875,0.9248,2829 Idaho,1.28223,3.25244,5.72559,0.39941,0.63142,0.80859,3924 Illinois,2.24023,5.61035,16.16504,0.437,1.05371,3.25977,29843 Indiana,1.58179,5.43067,15.16602,0.437,0.93359,3.064,14158 Iowa,1.38574,4.41983,10.11116,0.55566,0.78262,0.955,6962 Kansas,1.48926,4.43278,11.72461,0.44531,0.72266,2.77148,9302 Kentucky,2.00574,5.54678,10.0434,0.35547,0.75391,0.962,7449 Louisiana,2.3291,5.62854,11.21916,0.39746,1.069,2.75684,4107 Maine,1.94434,5.34131,11.9375,0.44922,0.488,0.91504,3528 Maryland,4.42482,13.16878,20.61907,1.18,3.79883,5.447,18822 Massachusetts,4.10645,11.71777,20.07031,0.95313,2.57715,4.48242,19303 Michigan,1.60059,5.59277,14.66504,0.47852,1.0459,2.62793,23926 Minnesota,2.26479,7.25098,16.79883,0.69336,1.03809,2.70508,16443 Mississippi,1.1866,3.20117,6.72348,0.2627,0.46191,1.868,2317 Missouri,1.75488,5.16499,13.01108,0.42188,0.90527,1.661,15561 Montana,1.23047,3.37109,7.67773,0.37207,0.53809,0.92773,2577 Nebraska,2.57422,6.71094,15.52734,0.51465,1.07,4.19531,5461 Nevada,2.69228,6.8686,16.42188,0.63379,2.23024,4.499,8234 New Hampshire,3.61621,9.46436,19.1416,0.677,1.93994,3.688,4284 New Jersey,3.88692,11.62503,19.57219,1.478,2.41895,4.48242,21259 New Mexico,1.29297,4.89983,10.49902,0.65918,0.8252,2.61328,5905 New York,3.10254,9.16406,16.61523,0.481,0.94043,2.02441,41962 North Carolina,2.76652,5.99316,12.06836,0.35449,0.47363,0.90527,23978 North Dakota,2.04702,5.29688,10.37305,0.51758,0.74316,1.06738,1037 Ohio,2.0166,5.40575,12.07003,0.439,0.571,0.91309,29860 Oklahoma,2.40808,5.06397,13.32227,0.435,1.25098,3.00977,6522 Oregon,1.87305,6.74023,16.96387,0.669,1.529,3.04785,14703 Pennsylvania,2.55359,8.16113,19.01758,0.59766,1.79297,4.155,27621 Rhode Island,6.1331,13.09866,20.2998,2.36523,4.91113,6.77539,2362 South Carolina,2.58301,5.89112,12.92676,0.35547,0.49,1.40723,8460 South Dakota,2.10039,7.80968,14.04102,0.62793,0.97678,1.94629,1472 Tennessee,2.51855,7.31219,16.53613,0.41797,1.42886,3.263,12306 Texas,2.4707,5.93066,14.84668,0.46289,0.91211,1.78906,44312 Utah,2.25541,5.8516,12.50391,0.66895,1.36475,3.4668,8076 Vermont,1.48633,2.91099,11.22852,0.461,0.732,2.50098,2342 Virginia,2.80176,10.93994,20.04102,0.7207,3.2627,4.83789,24662 Washington,2.24005,7.29883,17.2207,0.69922,1.89063,3.103,27469 West Virginia,1.60627,5.04606,10.74902,0.374,0.97628,1.93164,3084 Wisconsin,1.96102,6.8872,15.01563,0.44238,0.745,1.059,12972 Wyoming,1.30859,3.86426,8.13965,0.37598,0.51758,0.959,1001 """, 'mobile': """ Alabama,0.74707,2.04492,5.91797,0.32031,0.77148,2.02637,33075 Alaska,0.4668,1.36621,3.43457,0.23926,0.4707,0.94824,6891 Arizona,0.74707,2.18652,6.45313,0.40527,0.87891,3.26563,65815 Arkansas,0.68164,1.99756,5.63965,0.34473,0.70898,1.82715,16244 California,0.88086,2.58984,8.45215,0.40723,0.93164,2.88086,741884 Colorado,0.70801,2.16211,5.79883,0.39355,0.82031,3.25488,73203 Connecticut,1.03516,2.55957,7.92969,0.4082,1.06152,3.10547,36604 Delaware,1.22266,3.77441,12.13574,0.50781,1.75684,5.40137,9541 District of Columbia,0.84961,2.40186,7.58496,0.33984,0.94336,3.5332,25822 Florida,0.90137,2.43848,6.4043,0.35156,0.92383,2.22559,241011 Georgia,0.80566,2.32227,6.49121,0.33691,0.85156,2.63379,118613 Hawaii,0.7627,1.85547,4.92188,0.34375,0.85254,0.98047,17060 Idaho,0.73438,1.94141,5.06348,0.37793,0.6875,1.11816,12995 Illinois,0.86133,2.43262,7.46191,0.36426,0.90039,3.02734,185567 Indiana,0.81055,2.54785,9.02637,0.39844,0.90625,3.39258,62184 Iowa,0.76758,2.32276,7.06934,0.43164,0.80371,1.73242,25928 Kansas,0.46973,1.24902,2.96094,0.24414,0.60254,1.18555,245184 Kentucky,0.74902,2.13672,5.52246,0.35254,0.66016,1.05371,30738 Louisiana,0.13867,1.29102,4.16016,0.28418,0.75879,1.88281,14423 Maine,0.66797,1.89844,5.02441,0.4082,0.46973,0.92871,10189 Maryland,0.87988,2.75,9.99609,0.38965,1.24902,4.40527,111284 Massachusetts,1.05566,3.25977,9.7334,0.50781,1.54004,4.31836,71345 Michigan,0.63184,2.06348,6.15527,0.32031,0.80664,2.03027,106579 Minnesota,0.89355,2.64941,7.36426,0.4248,0.95996,2.7666,63713 Mississippi,0.48926,1.4873,3.69434,0.2666,0.4707,0.9043,8482 Missouri,0.85156,2.38086,5.77441,0.36035,0.79102,1.56543,71719 Montana,0.53027,1.54785,4.99316,0.36914,0.70898,1.63184,3018 Nebraska,0.60449,1.57422,4.81934,0.35352,0.75391,2.55957,12757 Nevada,0.88086,2.39209,6.03223,0.39648,0.91797,3.04297,39098 New Hampshire,1.09961,3.18262,9.1543,0.50879,1.55371,3.68359,9538 New Jersey,0.98145,2.80029,8.83594,0.45605,1.29785,3.90234,110858 New Mexico,0.68262,1.86523,5.06055,0.45117,0.78125,2.61816,13521 New York,0.89746,2.42383,7.0,0.37402,0.91797,1.98633,233091 North Carolina,0.9668,2.8877,8.00977,0.34766,0.72461,1.39648,82884 North Dakota,0.6709,1.99463,5.30957,0.45703,0.86084,1.9707,2666 Ohio,0.77441,2.28369,6.08203,0.35156,0.68848,1.26172,104274 Oklahoma,0.7793,2.19922,6.13672,0.33008,0.71191,2.51074,29231 Oregon,0.79785,2.4043,7.7959,0.38574,0.93945,3.16504,49491 Pennsylvania,0.91602,2.6875,8.15723,0.44824,1.02051,3.65332,133141 Rhode Island,0.7627,2.58936,8.47363,0.38379,1.21973,5.69141,8680 South Carolina,0.68164,2.04688,6.37109,0.34766,0.75684,1.78027,33827 South Dakota,0.58105,1.375,5.47852,0.30762,0.76465,2.65723,5251 Tennessee,0.8418,2.42871,6.42773,0.40039,0.99707,3.07715,51673 Texas,0.84277,2.40527,6.90039,0.35352,0.84082,1.65332,310136 Utah,0.64941,1.77588,4.75098,0.40723,0.82276,2.68262,38720 Vermont,0.8916,2.71777,8.07813,0.49902,1.23145,3.53027,6323 Virginia,0.94629,2.85547,10.43457,0.46191,1.35352,4.82422,118176 Washington,0.84766,2.34766,5.96289,0.38672,0.91602,2.36328,134694 West Virginia,0.78613,1.98096,6.19922,0.35938,0.84277,1.58398,12846 Wisconsin,0.55566,1.72852,6.86328,0.27148,0.62012,1.19336,52886 Wyoming,0.41113,1.2002,2.95898,0.37305,0.62061,0.87207,2658 """, 'business': """ Alabama,2.10286,6.47363,12.80273,1.239,2.857,6.01465,277 Alaska,3.06445,6.75977,23.26855,2.228,5.54395,11.68359,125 Arizona,3.1777,8.73516,21.62793,1.5918,5.74902,11.28809,501 Arkansas,2.73535,10.07715,17.50977,1.95313,6.315,11.783,157 California,2.3623,8.85303,31.87793,1.24902,3.45655,10.263,3450 Colorado,3.81492,8.96677,21.52637,1.95313,5.32937,9.364,790 Connecticut,2.32617,7.14746,19.33594,1.42676,2.84668,7.0459,276 Delaware,4.64063,19.95873,42.92773,1.4834,3.64649,5.53125,58 District of Columbia,6.90332,20.95752,39.7666,2.75781,7.69649,19.39941,840 Florida,3.25098,8.68115,21.38184,1.54883,4.1225,9.419,1086 Georgia,2.00977,8.31787,31.01367,1.29004,3.44922,8.99609,686 Hawaii,1.94434,5.32978,11.31348,0.75,1.88721,4.279,114 Idaho,1.60352,5.14648,16.7168,0.93262,2.79395,8.01172,156 Illinois,2.46574,8.30469,25.79957,1.37988,4.14853,10.0752,1106 Indiana,2.80667,7.04575,20.2998,1.677,5.29004,9.39258,477 Iowa,2.5373,6.36133,18.77803,1.11328,3.14907,9.16699,326 Kansas,1.24707,3.90326,16.93359,0.53516,2.20459,8.4873,504 Kentucky,3.04297,9.15252,21.75854,1.36328,4.91504,10.76758,317 Louisiana,3.5665,10.96191,23.67773,1.88,6.85547,14.855,159 Maine,4.15625,10.8916,18.1123,1.42285,2.61621,6.45605,173 Maryland,3.37598,10.05957,30.72949,1.47266,4.48047,10.2998,637 Massachusetts,2.97754,9.81836,26.88379,1.78809,4.16306,8.36523,730 Michigan,2.06081,6.67399,21.7702,1.281,2.899,8.13965,617 Minnesota,2.85836,10.77842,30.24689,1.719,5.14063,11.57129,679 Mississippi,1.45636,5.47559,11.64744,1.34961,2.403,7.96289,69 Missouri,3.17664,9.10352,21.83212,1.436,3.69141,11.26074,429 Montana,2.67773,5.67556,10.2373,1.01953,2.64697,6.37988,132 Nebraska,4.08789,8.94922,20.24609,1.23926,2.84863,8.10645,245 Nevada,2.78808,10.1997,25.32813,1.619,5.38867,12.79297,159 New Hampshire,2.03516,8.26119,14.60254,1.455,4.0155,8.81934,116 New Jersey,3.21986,10.61426,28.68945,1.9043,4.54883,10.54492,673 New Mexico,2.37207,4.77788,11.87305,1.48535,3.64063,8.00586,165 New York,3.84863,10.82129,31.57813,1.439,3.92139,9.58105,1692 North Carolina,3.125,9.35059,25.76758,2.01758,6.56543,15.29688,944 North Dakota,1.91211,6.14941,14.92449,1.16992,3.03027,8.401,79 Ohio,2.12361,5.62332,14.97754,0.9209,2.73243,8.87988,948 Oklahoma,1.63086,4.9345,21.38231,0.66406,2.74268,8.73047,354 Oregon,3.9366,9.32861,21.20029,1.43359,4.49122,9.12109,358 Pennsylvania,3.03027,9.61133,24.1091,1.487,4.1875,10.236,963 Rhode Island,4.97403,15.33105,22.05859,1.667,3.58496,6.12695,77 South Carolina,1.85156,7.14005,21.95703,1.327,4.04348,11.9082,242 South Dakota,6.49809,11.36888,25.44238,1.35742,3.60499,8.42969,124 Tennessee,2.97461,7.91162,19.91992,1.582,4.56592,9.48535,390 Texas,2.86328,9.3584,28.93246,1.63867,6.36426,15.03418,1518 Utah,6.15332,13.09961,23.86914,2.56641,7.158,13.19238,363 Vermont,2.80273,8.1748,16.81072,1.444,4.12109,19.47852,109 Virginia,3.75275,10.33008,31.64551,1.95313,5.54851,11.46875,1108 Washington,2.43555,10.63908,30.08496,1.17285,3.233,9.41016,887 West Virginia,0.99995,2.11523,10.54688,0.3252,1.01074,5.63086,115 Wisconsin,1.45703,5.82686,14.87109,1.095,2.69922,9.21094,430 Wyoming,2.01481,4.32042,11.41211,1.15723,3.40186,6.6582,48 """, 'cc_library_school': """ Alabama,4.3023,12.52469,30.46875,2.454,8.95069,14.41699,114 Alaska,3.89478,7.88256,16.63965,2.391,6.23242,8.312,35 Arizona,3.86824,9.66016,31.28516,1.63574,5.77637,11.894,219 Arkansas,1.9082,7.57818,17.71191,1.76074,7.19239,14.172,100 California,5.24121,18.33496,58.46973,2.91,8.11035,18.27637,1741 Colorado,4.14551,7.35762,14.38965,4.16113,5.33594,10.32031,493 Connecticut,4.0498,12.51325,24.17481,1.89648,5.71018,9.173,190 Delaware,20.50391,55.88935,74.17188,6.1543,16.42969,57.727,23 District of Columbia,7.48047,19.87549,49.02148,6.11133,13.26611,26.09277,116 Florida,5.07715,12.76033,25.93848,3.2002,7.23535,13.0498,553 Georgia,4.05176,14.20576,50.2998,3.15527,6.241,13.69629,509 Hawaii,3.60938,8.54883,14.07227,2.668,3.95605,4.70898,61 Idaho,1.15456,2.1582,5.36719,0.39648,0.5957,1.5459,933 Illinois,1.86485,6.3742,15.65527,0.954,2.608,8.71875,1523 Indiana,5.2002,15.49426,29.69791,3.03223,9.021,12.9541,448 Iowa,3.11035,10.36621,23.04004,1.18652,8.75781,13.09375,379 Kansas,4.6107,11.37964,23.24316,2.04492,7.5957,11.54102,143 Kentucky,8.60352,18.54541,34.63443,4.8584,11.89437,23.122,188 Louisiana,2.56055,7.70235,15.06543,1.376,8.348,13.7041,113 Maine,2.99021,8.88086,15.25488,1.2793,3.93653,6.63867,106 Maryland,4.89648,14.92253,51.7959,4.158,8.55469,21.362,293 Massachusetts,5.48202,14.04395,22.93164,2.89551,6.39258,9.61133,683 Michigan,5.19103,14.5096,38.27784,2.3623,7.9111,15.80859,610 Minnesota,2.00781,8.9115,24.58398,1.33301,4.23828,12.91211,636 Mississippi,4.48637,12.82882,16.96094,1.32617,3.14454,6.734,52 Missouri,3.06348,9.19092,24.85742,1.67285,4.20801,11.74316,238 Montana,1.41797,2.82773,5.52539,0.64648,1.80909,4.22266,136 Nebraska,4.31152,10.00221,23.45996,2.0459,6.84863,13.43359,149 Nevada,4.2832,18.30078,36.03418,2.49316,7.41895,20.05273,71 New Hampshire,2.21484,5.91699,18.28419,0.812,1.54004,5.56738,153 New Jersey,3.52886,9.81836,22.5625,1.57129,4.02246,8.56152,623 New Mexico,4.00684,7.60301,12.73633,2.78,4.44336,10.10742,95 New York,4.62891,12.90247,44.14844,1.87402,5.08205,9.89648,1110 North Carolina,3.34766,9.16406,18.21777,1.842,5.13477,8.6123,543 North Dakota,3.31282,6.66016,9.67188,1.02246,2.69434,6.269,41 Ohio,2.43652,6.28728,16.99707,1.92676,6.50879,12.4248,632 Oklahoma,5.30176,17.0337,23.94922,3.024,8.99219,11.92676,130 Oregon,3.57651,15.11621,26.68359,2.12793,7.35938,11.849,230 Pennsylvania,5.03613,14.71582,38.2832,2.10645,6.82569,14.758,658 Rhode Island,2.42676,5.85156,19.91699,0.66797,1.71289,8.59766,69 South Carolina,4.05958,13.71076,27.99512,1.4082,4.54541,10.10742,150 South Dakota,4.38477,11.61035,16.28906,0.8877,1.78223,3.27246,45 Tennessee,1.33789,8.63184,25.38782,1.885,5.17285,14.50488,239 Texas,3.01262,12.77504,42.08398,1.64648,7.0361,14.27637,606 Utah,9.80273,18.03027,25.78711,3.67578,8.19824,12.72852,219 Vermont,1.72717,5.30859,19.70508,0.873,2.58984,6.33105,41 Virginia,3.89648,12.59863,39.56543,2.45703,7.89648,17.03516,487 Washington,2.34723,9.21973,39.07324,1.60254,5.92578,11.40332,337 West Virginia,1.15228,7.48242,18.80469,0.85938,3.74414,9.37402,58 Wisconsin,7.62988,17.45642,45.43848,6.042,12.23291,16.792,312 Wyoming,2.24023,6.40321,11.36719,2.7793,5.2207,6.95801,25 """ } last_updated = '30.06.2014' source = '"Broadband Map", https://www.broadbandmap.gov/broadbandmap' broadband_type_of_interest = 'business' # home, mobile, business, cc_library_school state_of_interest = 'North Dakota' is_download = 1 is_download_label = 'download' if is_download else 'upload' labels = [] states_data = [] states_data_item = [] data = broadband_internet_types[broadband_type_of_interest] for idx, row in enumerate(data.split(' ')[1:-1]): state_name, lower_quartile_download, median_download, upper_quartile_download, lower_quartile_upload, median_upload, upper_quartile_upload, tests_done = row.split(',') states_data_item = [lower_quartile_download, median_download, upper_quartile_download] if is_download else [lower_quartile_upload, median_upload, upper_quartile_upload] states_data.append(list(map(float, states_data_item))) labels.append(state_name) of_interest_idx = labels.index(state_of_interest) states_data = np.array(states_data) scaled = MinMaxScaler().fit_transform(states_data) similarities = {} for idx, row in enumerate(states_data): if idx != of_interest_idx: similarities[labels[idx]] = cosine_similarity(states_data[of_interest_idx].reshape(1, -1), states_data[idx].reshape(1, -1))[0][0] print('Most similar states to %s in terms of %s speed (%s usage):' % (state_of_interest, is_download_label, broadband_type_of_interest)) for sidx, s in enumerate(sorted(similarities.items(), key = lambda x: x[1], reverse=True)[:3]): print("%d. %s" % (sidx+1, s[0])) print(' Last updated: %s Source: %s' % (last_updated, source)) """ Most similar states to North Dakota in terms of download speed (business usage): 1. Pennsylvania 2. Kentucky 3. Missouri Last updated: 30.06.2014 Source: "Broadband Map", https://www.broadbandmap.gov/broadbandmap """

Feel free to change the parameters to test the results with different states and usage scenarios.