diff --git a/code/02_models/04c_air_quality_model_final.ipynb b/code/02_models/04c_air_quality_model_final.ipynb index b930c9a..d2eaca6 100644 --- a/code/02_models/04c_air_quality_model_final.ipynb +++ b/code/02_models/04c_air_quality_model_final.ipynb @@ -12,28 +12,13 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 5, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/2f/fhks6w_d0k556plcv3rfmshw0000gn/T/ipykernel_2815/1880529722.py:1: UserWarning: Shapely 2.0 is installed, but because PyGEOS is also installed, GeoPandas will still use PyGEOS by default for now. To force to use and test Shapely 2.0, you have to set the environment variable USE_PYGEOS=0. You can do this before starting the Python process, or in your code before importing geopandas:\n", - "\n", - "import os\n", - "os.environ['USE_PYGEOS'] = '0'\n", - "import geopandas\n", - "\n", - "In a future release, GeoPandas will switch to using Shapely by default. If you are using PyGEOS directly (calling PyGEOS functions on geometries from GeoPandas), this will then stop working and you are encouraged to migrate from PyGEOS to Shapely 2.0 (https://shapely.readthedocs.io/en/latest/migration_pygeos.html).\n", - " import geopandas as gpd\n" - ] - } - ], + "outputs": [], "source": [ "import geopandas as gpd\n", "import numpy as np\n", - "import pickle\n", + "import joblib\n", "import libpysal\n", "import pandas as pd\n", "\n", @@ -44,7 +29,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -61,7 +46,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -501,7 +486,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -538,15 +523,17 @@ "name": "stderr", "output_type": "stream", "text": [ - "/Users/martin/mambaforge/envs/demoland/lib/python3.11/site-packages/libpysal/weights/weights.py:172: UserWarning: The weights matrix is not fully connected: \n", + "/var/folders/2f/fhks6w_d0k556plcv3rfmshw0000gn/T/ipykernel_44322/3672452686.py:1: FutureWarning: `use_index` defaults to False but will default to True in future. Set True/False directly to control this behavior and silence this warning\n", + " queen = libpysal.weights.Queen.from_dataframe(data)\n", + "/Users/martin/miniforge3/envs/demoland/lib/python3.11/site-packages/libpysal/weights/weights.py:224: UserWarning: The weights matrix is not fully connected: \n", " There are 51 disconnected components.\n", " There are 19 islands with ids: 1676, 2132, 3036, 21306, 33133, 34428, 42635, 42654, 68863, 72800, 74393, 105153, 108399, 134057, 140649, 141143, 141475, 144653, 149708.\n", " warnings.warn(message)\n", - "/Users/martin/mambaforge/envs/demoland/lib/python3.11/site-packages/libpysal/weights/weights.py:172: UserWarning: The weights matrix is not fully connected: \n", + "/Users/martin/miniforge3/envs/demoland/lib/python3.11/site-packages/libpysal/weights/weights.py:224: UserWarning: The weights matrix is not fully connected: \n", " There are 5289 disconnected components.\n", " There are 3592 islands with ids: 2922, 2953, 3591, 12424, 12425, 12427, 12742, 12744, 13181, 13182, 13278, 13409, 13960, 14168, 14924, 15712, 15729, 15731, 15733, 28156, 28170, 28272, 28288, 28309, 28480, 28638, 28648, 29700, 31495, 31496, 33251, 33357, 34067, 34099, 34140, 34428, 34748, 35053, 35055, 35056, 35057, 35217, 35218, 36381, 36383, 37762, 37767, 37769, 37786, 37804, 37809, 38033, 38074, 38075, 38076, 38077, 38086, 38087, 38088, 38089, 38091, 38094, 38099, 38104, 38115, 38116, 38117, 38118, 38119, 38121, 38236, 38237, 38251, 38252, 38260, 38261, 38277, 38279, 38283, 38294, 38295, 38296, 38318, 38320, 38322, 38323, 38324, 38335, 38339, 38340, 38392, 38393, 38422, 38469, 38547, 38557, 38558, 38561, 38564, 38572, 38586, 38587, 38588, 38758, 38759, 38760, 38761, 38762, 38763, 38766, 38767, 38769, 38790, 38791, 38792, 38793, 38797, 38799, 39246, 39248, 39249, 39358, 39373, 39374, 39381, 39397, 39402, 39497, 39499, 39508, 39509, 39527, 39591, 39593, 39664, 39671, 39739, 39769, 41874, 41875, 41876, 41885, 41889, 41890, 41910, 41912, 41914, 41916, 41917, 41918, 41956, 42873, 42881, 42882, 42883, 42884, 42885, 42886, 42902, 42903, 42904, 42905, 42906, 42919, 42920, 42921, 42922, 42923, 42945, 42946, 42950, 42951, 42953, 42954, 42957, 42958, 42959, 42970, 42971, 42972, 42973, 42974, 42975, 42979, 42980, 42981, 42985, 42986, 42987, 42988, 42997, 43006, 43007, 43008, 43009, 43010, 43015, 43020, 43055, 43129, 43130, 43131, 43132, 43135, 43136, 43137, 43138, 43139, 43140, 43141, 43145, 43146, 43151, 43154, 43158, 43159, 43160, 43161, 43162, 43163, 43166, 43170, 43171, 43172, 43182, 43183, 43185, 43189, 43190, 43191, 43375, 43376, 43379, 43382, 43385, 43395, 43396, 43397, 43402, 43444, 43453, 43538, 43539, 43557, 43564, 43858, 43860, 44734, 44749, 44784, 44932, 46469, 47014, 47056, 47111, 47112, 47223, 47224, 47229, 47563, 50113, 50360, 50670, 50807, 50808, 50861, 52981, 53797, 53833, 53836, 53845, 53919, 53927, 53928, 53929, 53932, 53933, 53934, 53935, 53936, 53988, 54002, 54003, 54004, 54010, 54019, 54106, 55304, 56271, 56273, 56281, 56282, 58658, 58662, 58663, 58683, 58688, 58689, 58959, 59162, 59301, 59304, 59416, 59425, 59426, 59657, 59813, 59814, 59815, 59816, 59821, 59822, 59823, 59826, 59828, 59829, 59830, 59831, 59841, 59917, 60296, 60301, 60444, 60448, 60452, 60453, 60455, 60456, 60502, 60504, 60532, 60537, 60572, 60573, 60623, 60629, 60630, 60634, 60640, 60641, 60704, 60705, 60706, 60713, 62048, 62052, 62054, 62059, 62063, 62066, 62067, 62069, 62080, 62081, 62117, 62133, 62159, 62163, 62181, 62204, 62223, 62246, 62247, 62252, 62256, 62286, 62335, 62357, 62393, 62409, 62434, 62437, 62502, 62511, 62570, 62571, 62572, 62573, 62577, 62617, 62629, 62700, 62712, 62718, 62719, 62876, 62877, 62878, 62895, 62896, 62900, 62914, 62943, 62950, 62958, 62997, 63004, 63007, 63023, 63050, 63057, 63058, 63059, 63061, 63099, 63125, 63137, 63139, 63265, 63272, 63318, 63364, 63374, 63544, 63650, 63660, 63726, 63728, 63730, 63741, 63744, 63745, 63958, 64107, 64109, 64111, 64112, 64113, 64139, 64141, 64180, 64209, 64285, 64288, 64290, 64291, 64292, 64296, 64444, 64448, 64449, 64828, 64834, 64869, 64870, 64871, 64872, 65134, 65156, 65225, 65231, 65232, 65234, 65238, 65415, 65421, 65498, 65506, 65663, 65671, 65672, 65677, 65678, 65679, 65680, 65705, 65706, 65710, 65711, 65767, 65769, 65771, 65780, 65801, 65809, 65810, 65813, 65950, 65955, 66101, 66108, 66130, 66131, 66132, 66138, 66268, 66398, 66402, 66406, 66489, 66490, 66500, 66508, 66509, 66510, 66515, 66516, 66517, 66518, 66519, 66520, 66521, 66522, 66525, 66590, 66610, 66611, 66612, 66613, 66614, 66615, 66620, 66643, 66644, 66648, 66650, 66651, 66671, 66675, 66704, 66705, 66706, 66717, 66721, 66727, 66729, 66731, 66732, 66733, 66734, 66735, 66736, 66737, 66745, 66770, 66771, 66772, 66773, 66857, 66860, 66861, 66866, 66883, 66957, 66961, 66962, 67063, 67139, 67218, 67241, 67253, 67254, 67258, 67273, 67341, 67352, 67354, 67355, 67356, 67357, 67358, 67386, 67387, 67388, 67389, 67390, 67391, 67392, 67393, 67394, 67395, 67401, 67402, 67403, 67454, 67455, 67456, 67474, 67476, 67478, 67479, 67573, 67584, 67585, 67587, 67595, 67597, 67600, 67601, 67602, 67603, 67604, 67605, 67606, 67607, 67608, 67609, 67611, 67612, 67613, 67614, 67845, 67941, 67985, 67993, 67995, 67997, 68022, 68023, 68024, 68025, 68051, 68056, 68057, 68058, 68059, 68060, 68061, 68062, 68070, 68071, 68072, 68073, 68074, 68075, 68076, 68077, 68078, 68125, 68126, 68127, 68129, 68187, 68213, 68222, 68224, 68301, 68302, 68303, 68314, 68376, 68377, 68379, 68425, 68426, 68427, 68434, 68435, 68436, 68440, 68451, 68452, 68453, 68454, 68458, 68459, 68460, 68461, 68462, 68463, 68464, 68468, 68474, 68475, 68476, 68479, 68480, 68481, 68482, 68483, 68484, 68485, 68487, 68488, 68489, 68490, 68497, 68498, 68499, 68500, 68503, 68504, 68506, 68507, 68508, 68509, 68510, 68511, 68512, 68513, 68518, 68520, 68521, 68524, 68525, 68526, 68527, 68528, 68529, 68532, 68559, 68586, 68587, 68588, 68589, 68594, 68595, 68596, 68597, 68598, 68599, 68600, 68601, 68602, 68603, 68605, 68606, 68607, 68608, 68609, 68627, 68628, 68630, 68631, 68639, 68653, 68657, 68662, 68667, 68670, 68671, 68672, 68694, 68695, 68696, 68697, 68698, 68699, 68797, 68798, 68812, 68813, 68819, 68842, 68843, 68844, 68845, 68848, 68856, 68863, 68864, 68865, 68870, 68871, 68873, 68876, 68877, 68878, 68879, 68880, 68926, 68927, 68928, 68929, 68930, 68931, 68932, 68938, 68996, 69324, 69325, 69963, 69964, 69972, 69975, 69976, 69981, 69987, 69988, 70012, 70014, 70015, 70023, 70024, 70025, 70026, 70050, 70051, 70106, 70107, 70108, 70109, 70110, 70123, 70637, 70645, 70649, 70669, 70725, 70771, 70805, 70814, 70819, 71291, 71294, 71308, 71423, 71426, 71428, 71429, 71461, 71475, 71476, 71477, 71478, 71479, 71487, 71492, 71605, 71652, 71658, 71659, 71667, 71668, 71669, 71670, 71671, 71672, 71702, 71703, 71705, 71784, 71785, 71786, 71787, 71788, 71821, 71824, 71825, 71826, 71827, 72203, 72204, 72205, 72212, 72213, 72214, 72215, 72222, 72231, 72238, 72239, 72240, 72241, 72242, 72272, 72278, 72292, 72295, 72334, 72345, 72346, 72351, 72358, 72359, 72360, 72361, 72362, 72363, 72369, 72377, 72379, 72385, 72386, 72389, 72390, 72409, 72410, 72411, 72413, 72415, 72433, 72434, 72436, 72438, 72439, 72440, 72444, 72445, 72446, 72447, 72490, 72491, 72493, 72495, 72496, 72497, 72498, 72502, 72504, 72511, 72516, 72517, 72597, 72600, 72609, 72613, 72629, 72631, 72635, 72636, 72637, 72638, 72639, 72654, 72655, 72656, 72686, 72687, 72688, 72692, 72707, 72708, 72709, 72711, 72714, 72715, 72716, 72721, 72734, 72735, 72736, 72740, 72741, 72744, 72746, 72785, 72791, 72792, 72793, 72794, 72795, 72797, 72801, 72802, 72811, 72892, 72893, 72895, 72914, 72969, 72970, 72971, 72972, 72973, 73009, 73063, 73064, 73136, 73206, 73207, 73218, 73237, 73241, 73268, 73305, 73311, 73321, 73328, 73381, 73387, 73390, 73415, 73450, 73451, 73452, 73453, 73454, 73457, 73458, 73459, 73465, 73466, 73467, 73468, 73469, 73470, 73471, 73472, 73475, 73476, 73486, 73487, 73496, 73497, 73498, 73499, 73501, 73502, 73503, 73505, 73508, 73533, 73534, 73535, 73537, 73538, 73539, 73541, 73542, 73546, 73569, 73570, 73571, 73572, 73573, 73574, 73582, 73583, 73584, 73599, 73600, 73601, 73602, 73603, 73616, 73619, 73620, 73626, 73627, 73628, 73629, 73630, 73631, 73632, 73633, 73634, 73635, 73636, 73642, 73643, 73644, 73645, 73650, 73651, 73652, 73656, 73657, 73658, 73659, 73660, 73661, 73676, 73687, 73689, 73690, 73691, 73735, 73744, 73745, 73872, 73985, 74020, 74021, 74022, 74023, 74028, 74029, 74030, 74031, 74032, 74087, 74189, 74198, 74199, 74200, 74201, 74210, 74250, 74251, 74252, 74253, 74257, 74258, 74269, 74277, 74286, 74290, 74291, 74367, 74369, 74387, 74395, 74400, 74401, 74405, 74419, 74451, 74509, 74510, 74513, 74515, 74516, 74544, 74548, 74600, 74603, 74610, 74627, 74629, 74635, 74639, 74640, 74666, 74723, 74727, 74729, 74730, 74733, 74734, 74739, 74753, 74755, 74759, 74760, 74761, 74762, 74763, 74779, 74786, 74787, 74790, 74791, 74792, 74793, 74794, 74799, 74805, 74807, 74841, 74842, 75357, 75452, 76253, 76254, 76259, 76393, 76394, 76400, 76401, 76402, 76403, 76404, 76414, 76425, 76427, 76428, 76429, 76430, 76437, 76438, 76443, 76444, 76445, 76446, 76447, 76448, 76456, 76457, 76563, 76564, 76565, 76566, 76569, 76570, 76572, 77283, 77311, 77316, 77415, 77416, 77480, 77487, 77591, 77638, 77649, 77650, 77658, 77679, 77680, 77681, 77828, 77878, 77887, 77889, 77900, 77982, 77985, 77986, 77992, 78026, 78029, 78035, 78095, 78104, 78105, 78135, 78182, 79017, 79125, 79126, 79127, 79134, 79140, 79158, 79172, 79173, 79174, 79177, 79208, 79214, 79222, 79377, 79442, 79852, 79884, 79885, 79888, 80328, 80339, 80413, 80562, 80931, 81066, 81083, 81450, 81462, 81479, 81572, 81596, 81601, 81650, 81951, 82176, 82317, 82384, 82385, 82451, 82533, 82541, 82550, 82568, 82569, 82572, 82576, 82577, 82579, 82587, 82967, 82970, 82975, 82978, 82980, 82989, 83018, 83032, 83034, 83036, 83037, 83038, 83040, 83041, 83042, 83043, 83044, 83105, 83106, 83107, 83108, 83109, 83110, 83111, 83125, 83130, 83131, 83132, 83133, 83134, 83135, 83137, 83138, 83170, 83173, 83177, 83178, 83179, 83180, 83181, 83185, 83187, 83211, 83212, 83214, 83215, 83216, 83217, 83218, 83274, 83275, 83278, 83348, 83349, 83448, 83449, 83450, 83474, 83476, 83490, 83860, 83990, 84005, 84006, 84007, 84008, 84080, 84164, 84167, 84317, 84318, 84331, 84342, 84343, 84356, 84359, 84360, 84362, 84382, 84431, 84432, 84552, 84553, 84573, 84657, 84689, 84729, 84872, 84874, 84875, 84876, 84877, 84895, 84974, 85015, 85016, 85019, 85020, 85026, 85027, 85028, 85047, 85049, 85050, 85085, 85087, 85194, 85212, 85218, 86260, 86393, 86896, 86907, 86908, 86912, 86913, 86928, 86946, 86948, 87000, 87005, 87072, 87073, 87076, 87300, 87689, 87741, 87744, 87796, 87800, 87801, 87802, 87807, 87808, 87810, 87896, 88022, 88025, 88026, 88027, 88028, 88082, 88084, 88091, 88136, 88138, 88275, 88294, 88300, 88318, 88319, 89009, 89147, 89152, 89155, 89171, 89236, 89314, 89318, 89368, 89377, 89740, 89790, 89793, 89794, 89796, 89920, 89922, 90107, 90108, 90404, 91645, 91668, 91669, 91671, 91672, 91673, 91706, 91756, 91781, 91836, 91881, 91931, 91975, 91978, 91979, 92134, 92135, 92678, 92693, 92707, 93459, 93472, 93474, 93534, 93568, 93571, 93572, 93574, 93697, 93714, 93715, 93720, 93882, 94333, 94334, 94337, 94339, 94340, 94423, 94480, 94704, 95571, 95581, 95591, 95594, 95855, 95897, 96409, 96603, 96651, 96662, 97026, 97031, 97035, 97147, 97156, 97164, 97165, 97167, 97169, 97329, 97333, 97335, 97337, 97524, 97896, 97897, 98074, 98075, 98076, 98081, 98082, 98083, 98105, 98126, 98127, 98128, 98205, 98207, 98823, 98824, 99160, 99161, 99241, 99364, 99366, 99478, 100037, 100223, 100224, 100225, 100226, 100231, 100234, 100292, 100309, 100312, 100316, 100415, 100417, 100423, 100424, 100429, 100432, 100451, 100457, 100574, 100780, 100781, 100811, 100813, 100817, 100818, 100819, 100821, 100823, 100824, 100919, 100920, 100925, 100926, 100927, 100928, 100936, 100937, 100938, 100939, 100947, 101183, 101393, 101410, 101436, 101451, 101472, 101526, 101527, 101528, 101581, 101587, 101590, 101600, 101613, 101618, 101634, 101636, 101638, 101641, 101642, 101644, 101645, 101654, 101656, 101696, 101697, 101701, 101702, 101703, 101704, 101712, 101713, 101718, 101720, 101721, 101722, 101724, 101725, 101726, 101727, 101728, 101754, 101762, 101777, 101795, 101796, 101797, 101798, 101799, 101800, 101802, 101892, 101897, 101898, 101906, 101907, 101908, 101927, 101928, 101929, 101930, 101931, 101932, 101934, 101935, 101936, 101970, 101972, 101975, 101976, 101977, 101978, 101979, 101997, 101998, 101999, 102001, 102002, 102003, 102016, 102017, 102018, 102297, 102302, 102303, 102306, 102356, 102360, 102368, 102381, 102383, 102388, 102395, 102404, 102428, 102429, 102433, 102434, 102441, 102442, 102443, 102444, 102447, 102450, 102505, 102506, 102507, 102508, 102509, 102511, 102512, 102607, 102608, 102609, 102620, 102630, 102637, 102647, 102658, 102700, 102706, 102709, 102802, 102809, 102818, 102823, 102841, 102872, 102875, 102876, 102879, 102904, 102985, 102995, 102997, 102998, 102999, 103001, 103066, 103071, 103077, 103078, 103079, 103080, 103081, 103082, 103086, 103087, 103092, 103093, 103135, 103207, 103252, 103259, 103260, 103261, 103262, 103266, 103269, 103279, 103280, 103300, 103301, 103303, 103306, 103307, 103308, 103362, 103365, 103367, 103370, 103371, 103372, 103376, 103377, 103378, 103386, 103398, 103401, 103406, 103407, 103408, 103421, 103440, 103441, 103448, 103450, 103451, 103459, 103490, 103495, 103497, 103498, 103499, 103502, 103514, 103515, 103518, 103519, 103532, 103533, 103534, 103535, 103555, 103617, 103618, 103629, 103635, 103645, 103650, 103655, 103657, 103661, 103662, 103663, 103664, 103665, 103673, 103709, 103723, 103748, 103762, 103766, 103819, 103848, 103850, 103851, 103852, 103857, 103858, 103859, 103860, 103890, 103891, 103892, 103893, 103895, 103896, 103909, 103950, 103954, 103972, 104045, 104046, 104047, 104051, 104052, 104054, 104055, 104471, 104472, 104609, 104613, 104638, 104651, 104660, 104668, 104671, 104707, 104756, 104801, 104826, 104829, 104854, 104888, 104903, 104904, 104905, 104906, 104907, 104908, 104909, 104912, 104942, 104943, 104996, 105008, 105009, 105010, 105014, 105019, 105020, 105022, 105026, 105038, 105069, 105071, 105072, 105079, 105083, 105086, 105087, 105089, 105093, 105099, 105105, 105106, 105107, 105109, 105115, 105117, 105141, 105142, 105143, 105155, 105156, 105165, 105287, 105288, 105289, 105290, 105381, 105385, 105387, 105398, 105406, 105427, 105428, 105429, 105435, 105440, 105874, 105883, 105884, 105885, 105901, 105907, 105929, 105930, 105940, 106030, 106053, 106152, 106224, 106237, 106445, 106491, 106492, 106498, 106499, 106500, 106503, 106504, 106536, 106566, 106586, 106593, 106600, 106601, 106611, 106612, 106622, 106634, 106636, 106637, 106641, 106642, 106643, 106644, 106646, 106650, 106652, 106701, 106706, 106709, 106711, 106717, 106723, 106740, 106862, 106941, 106943, 107089, 107140, 107141, 107143, 107144, 107145, 107780, 107782, 107783, 107784, 107835, 107957, 107962, 107992, 107999, 108002, 108004, 108005, 108006, 108007, 108250, 108307, 108308, 108309, 108310, 108311, 108312, 108313, 108314, 108315, 108316, 108321, 108326, 108327, 108328, 108338, 108339, 108347, 108349, 108357, 108358, 108359, 108360, 108361, 108364, 108367, 108368, 108373, 108374, 108375, 108385, 108392, 108393, 108394, 108395, 108397, 108399, 108400, 108406, 108409, 108410, 108411, 108412, 108415, 108455, 108737, 108738, 108739, 108740, 108741, 108752, 108756, 108811, 108835, 108855, 108856, 108859, 108860, 108862, 108863, 108881, 108882, 108883, 108893, 108895, 108906, 108907, 108912, 108914, 108915, 108916, 108935, 108977, 109016, 109017, 109019, 109020, 109021, 109025, 109026, 109040, 109041, 109042, 109043, 109044, 109045, 109046, 109048, 109051, 109054, 109055, 109056, 109057, 109058, 109277, 109278, 109279, 109280, 109282, 109283, 109284, 109311, 109312, 109313, 109319, 109320, 109321, 109322, 109340, 109341, 109349, 109350, 109351, 109352, 109355, 109360, 109361, 109366, 109367, 109368, 109369, 109370, 109380, 109444, 109445, 109446, 109447, 109448, 109451, 109455, 109481, 109483, 109486, 109487, 109488, 109489, 109492, 109493, 109494, 109520, 109527, 109532, 109535, 109536, 109540, 109544, 109545, 109555, 109558, 109560, 109601, 109602, 109603, 109607, 109623, 109629, 109630, 109632, 109638, 109639, 109651, 109652, 109674, 109675, 109676, 109679, 109680, 109681, 109682, 109683, 109704, 109707, 109710, 109722, 109726, 109727, 109728, 109729, 109730, 109731, 109733, 109774, 109775, 109782, 109869, 109870, 109874, 109875, 109877, 109879, 109968, 109970, 109971, 109974, 109982, 109987, 109989, 110013, 110014, 110018, 110019, 110024, 110045, 110051, 110054, 110055, 110058, 110066, 110155, 110156, 110205, 110207, 110208, 110210, 110213, 110214, 110215, 110216, 110220, 110223, 110226, 110249, 110250, 110251, 110252, 110258, 110259, 110260, 110261, 110262, 110289, 110290, 110296, 110299, 110301, 110304, 110315, 110316, 110317, 110318, 110319, 110320, 110322, 110325, 110329, 110333, 110335, 110336, 110337, 110338, 110340, 110341, 110342, 110343, 110344, 110345, 110346, 110347, 110381, 110382, 110383, 110384, 110388, 110389, 110394, 110395, 110396, 110397, 110400, 110403, 110404, 110405, 110406, 110407, 110408, 110409, 110410, 110411, 110412, 110413, 110414, 110415, 110418, 110419, 110421, 110427, 110429, 110430, 110431, 110432, 110433, 110434, 110510, 110515, 110517, 110522, 110523, 110524, 110528, 110529, 110531, 110537, 110538, 110539, 110540, 110541, 110542, 110544, 110545, 110546, 110547, 110548, 110553, 110557, 110558, 110559, 110560, 110561, 110562, 110611, 110613, 110616, 110617, 110618, 110647, 110648, 110657, 110658, 110661, 110662, 110711, 110725, 110758, 110829, 110830, 110843, 110929, 110933, 110934, 111005, 111062, 111063, 111075, 111078, 111158, 111172, 111178, 111179, 111587, 111589, 111590, 111675, 111712, 111741, 111746, 111748, 111752, 111763, 112484, 112996, 113070, 113071, 113074, 113096, 113100, 113101, 113134, 113149, 113161, 113194, 113201, 113262, 113274, 113275, 113515, 113567, 113569, 113570, 113622, 113625, 113639, 113883, 113889, 113892, 113909, 113914, 113923, 113972, 113986, 113987, 113991, 113994, 114007, 114019, 114020, 114417, 114459, 114504, 114577, 114769, 114772, 114774, 114928, 114934, 115056, 115057, 115061, 115167, 115168, 115169, 115171, 115174, 115332, 115336, 115337, 115338, 115352, 115364, 115481, 115545, 115546, 115547, 115548, 115549, 115557, 115558, 115559, 115560, 115561, 115565, 115567, 115568, 115580, 115581, 115582, 115592, 115614, 115615, 115620, 115621, 115625, 115626, 115643, 115644, 115645, 115650, 115666, 115669, 115675, 115676, 115677, 115678, 115679, 115681, 115683, 115684, 115685, 115722, 115729, 115730, 115731, 115732, 115741, 115752, 115753, 115755, 115778, 115779, 115803, 115808, 115870, 115871, 115874, 115875, 115896, 115907, 115913, 116048, 116050, 116097, 116099, 116102, 116103, 116104, 116106, 116107, 116108, 116109, 116112, 116113, 116150, 116153, 116187, 116193, 116194, 116195, 116199, 116200, 116201, 116203, 116208, 116209, 116210, 116258, 116260, 116261, 116269, 116270, 116271, 116272, 116273, 116275, 116276, 116277, 116280, 116281, 116287, 116288, 116291, 116292, 116293, 116309, 116313, 116316, 116325, 116329, 116330, 116331, 116332, 116333, 116334, 116335, 116336, 116337, 116338, 116339, 116384, 116385, 116386, 116389, 116390, 116391, 116392, 116395, 116397, 116398, 116399, 116416, 116417, 116418, 116576, 116577, 116579, 116589, 116599, 116600, 116603, 116604, 116608, 116609, 116610, 116613, 116617, 116618, 116619, 116701, 116703, 116704, 116749, 116926, 116936, 116937, 116947, 116950, 116951, 116977, 116978, 117067, 117077, 117092, 117098, 117099, 117105, 117106, 117107, 117108, 117117, 117149, 117166, 117181, 117235, 117313, 117329, 117386, 117429, 117431, 117437, 117438, 117463, 117480, 117483, 117634, 117635, 117636, 117671, 117673, 117674, 117679, 117689, 117690, 117692, 117698, 117939, 117940, 117941, 117964, 117967, 117968, 117969, 117970, 117975, 117980, 117985, 117987, 117991, 117992, 117993, 118020, 118021, 118022, 118024, 118029, 118035, 118036, 118045, 118046, 118047, 118048, 118063, 118364, 118365, 118367, 118395, 118396, 118397, 118456, 118538, 118657, 118688, 118689, 118873, 118875, 118906, 118913, 119165, 119173, 119175, 119178, 119181, 119539, 119580, 119607, 119652, 119660, 119742, 119747, 119748, 119780, 119781, 119783, 119785, 119794, 119795, 119843, 119845, 119849, 119850, 119962, 119965, 119966, 120009, 120010, 120011, 120018, 120034, 120042, 120193, 120257, 120284, 120285, 120286, 120287, 120288, 120309, 120310, 120317, 120318, 120392, 120393, 120394, 120395, 120396, 120397, 120398, 120667, 120668, 120669, 120674, 120675, 120676, 120698, 120699, 120777, 120802, 120810, 120815, 120837, 120861, 120863, 120864, 120950, 120966, 120968, 120998, 121018, 121079, 121467, 121471, 121473, 121506, 121543, 121544, 121545, 121551, 121565, 121568, 121569, 121573, 121575, 121582, 121610, 121697, 121707, 121718, 121726, 121734, 121736, 121737, 121762, 121763, 121766, 121775, 121784, 121791, 121792, 121798, 121800, 121910, 121973, 121975, 122048, 122049, 122050, 122055, 122056, 122077, 122078, 122079, 122080, 122082, 122187, 122195, 122196, 122201, 122205, 122299, 122312, 122316, 122317, 122321, 122322, 122326, 122327, 122328, 122329, 122330, 122334, 122335, 122378, 122394, 122395, 122397, 122398, 122422, 122423, 122444, 122445, 122486, 122490, 122494, 122651, 122771, 122772, 122773, 122775, 122776, 122779, 122783, 122784, 122829, 122831, 123966, 123967, 123972, 125425, 125572, 125584, 125601, 125645, 125646, 125647, 126324, 126340, 126348, 126823, 126903, 126960, 126961, 126995, 126996, 126998, 127073, 127076, 127098, 127106, 127138, 127139, 127142, 127160, 127161, 127163, 127168, 127171, 127201, 127224, 127229, 127264, 127265, 127410, 127418, 127425, 127426, 127533, 127535, 127608, 127696, 127735, 128138, 128139, 128579, 128582, 128586, 128587, 128726, 128732, 128733, 128739, 128740, 128772, 128788, 128794, 128795, 128878, 128879, 128880, 128920, 129251, 129270, 129297, 129307, 129341, 129342, 129346, 129472, 129760, 129985, 130006, 130388, 130391, 130399, 130403, 130426, 130427, 130430, 130469, 130474, 130512, 130514, 130515, 130516, 130517, 130518, 130524, 130525, 130539, 130542, 130543, 130544, 130552, 130553, 130566, 130569, 130570, 130573, 130588, 130602, 130606, 130614, 130617, 130635, 130649, 130700, 130844, 130847, 130848, 130865, 130867, 130868, 130894, 130895, 130899, 130900, 130921, 130931, 131075, 131078, 131081, 131088, 131101, 131126, 131129, 131151, 131178, 131179, 131181, 131183, 131184, 131185, 131197, 131198, 131201, 131202, 131203, 131271, 131272, 131276, 131278, 131279, 131280, 131281, 131282, 131283, 131284, 131289, 131297, 131299, 131300, 131301, 131304, 131309, 131315, 131316, 131348, 131416, 131431, 131507, 131508, 131513, 131515, 131516, 131536, 131537, 131541, 131552, 131957, 132029, 132035, 132036, 132086, 132087, 132088, 132092, 132093, 132116, 132117, 132119, 132152, 132184, 132185, 132188, 132192, 132193, 132194, 132251, 132953, 133049, 133065, 133066, 133144, 133155, 133170, 133171, 133251, 133443, 133632, 133918, 134086, 134218, 134219, 134464, 134932, 135404, 135409, 135420, 135425, 135441, 135449, 135751, 135753, 135754, 135820, 135850, 135955, 136140, 136141, 136170, 136184, 136212, 136535, 136564, 136565, 136567, 136723, 136730, 136735, 136736, 136749, 137405, 137456, 137457, 137613, 137899, 138280, 138321, 138326, 138380, 138607, 138608, 138714, 138934, 138987, 139137, 139140, 139189, 139391, 139554, 139601, 139905, 139906, 139941, 140032, 140076, 140946, 140947, 141195, 141196, 141216, 141217, 141219, 141221, 141288, 141289, 141296, 141297, 141298, 141299, 141301, 141302, 141303, 141317, 141323, 141328, 141332, 141333, 141347, 141348, 141354, 141385, 141415, 141416, 141417, 141422, 141434, 141440, 141461, 141470, 141471, 141472, 141473, 141474, 141475, 141476, 141477, 141485, 141486, 141487, 141490, 141491, 141508, 141520, 141521, 141522, 141540, 141541, 141558, 141568, 141569, 141580, 141583, 141586, 141587, 141588, 141589, 141594, 141600, 141601, 141602, 141603, 141607, 141611, 141612, 141618, 141625, 141634, 141635, 141639, 141685, 141718, 141719, 141720, 141748, 141759, 141763, 141771, 141772, 141773, 141787, 141810, 141811, 141812, 141813, 141816, 141824, 141825, 141826, 141827, 141899, 141902, 141927, 142014, 142015, 142016, 142017, 142026, 142027, 142028, 142029, 142030, 142149, 142150, 142151, 142169, 142170, 142171, 142172, 142173, 142174, 142175, 142176, 142177, 142189, 142193, 142194, 142232, 142233, 142234, 142236, 142237, 142238, 142239, 142240, 142241, 142242, 142243, 142251, 142252, 142258, 142261, 142264, 142278, 142279, 142280, 142284, 142613, 142614, 142616, 142958, 142989, 142990, 142991, 142992, 143040, 143042, 143047, 143166, 143167, 143217, 143259, 143260, 143262, 143284, 143290, 143378, 143379, 143380, 143381, 143382, 143383, 143384, 143386, 143387, 143389, 143390, 143391, 143393, 143394, 143395, 143399, 143408, 143409, 143413, 143415, 143416, 143418, 143420, 143421, 143436, 143438, 143439, 143441, 143442, 143443, 143445, 143447, 143449, 143450, 143452, 143453, 143454, 143455, 143456, 143457, 143458, 143459, 143461, 143462, 143463, 143469, 143470, 143471, 143472, 143473, 143481, 143483, 143484, 143495, 143499, 143500, 143501, 143502, 143505, 143506, 143507, 143508, 143509, 143510, 143511, 143512, 143513, 143530, 143531, 143532, 143533, 143535, 143541, 143542, 143543, 143546, 143551, 143552, 143553, 143554, 143556, 143557, 143559, 143560, 143561, 143562, 143563, 143564, 143565, 143567, 143579, 143580, 143581, 143582, 143583, 143584, 143585, 143586, 143587, 143588, 143595, 143596, 143598, 143600, 143601, 143603, 143604, 143613, 143614, 143615, 143617, 143619, 143620, 143621, 143622, 143625, 143626, 143627, 143628, 143629, 143663, 143664, 143665, 143666, 143667, 143675, 143677, 143684, 143685, 143686, 143715, 143716, 143717, 143718, 143719, 143724, 143727, 143730, 143731, 143735, 143762, 143763, 143767, 143837, 143838, 143839, 143841, 143850, 143851, 143852, 143853, 143854, 143855, 143860, 143881, 143884, 143894, 143898, 143899, 143900, 143901, 143912, 143915, 143917, 143918, 143920, 143921, 143922, 143923, 143924, 143925, 143926, 143930, 143932, 143933, 143934, 143935, 143936, 143937, 143938, 143940, 143941, 143948, 143949, 143950, 143951, 143953, 143954, 143955, 143956, 143957, 143958, 143959, 143960, 143963, 143964, 143965, 143966, 143972, 143975, 143976, 143979, 143982, 143993, 143999, 144001, 144002, 144005, 144006, 144007, 144008, 144009, 144010, 144011, 144012, 144024, 144025, 144030, 144035, 144038, 144039, 144040, 144043, 144044, 144045, 144049, 144050, 144051, 144052, 144056, 144057, 144064, 144120, 144121, 144122, 144124, 144142, 144143, 144149, 144153, 144154, 144164, 144165, 144166, 144169, 144170, 144171, 144172, 144173, 144185, 144186, 144187, 144328, 144332, 144334, 144335, 144336, 144342, 144344, 144359, 144361, 144362, 144378, 144390, 144392, 144393, 144396, 144399, 144401, 144404, 144405, 144510, 144511, 144513, 144517, 144518, 144519, 144520, 144521, 144522, 144525, 144526, 144527, 144528, 144529, 144530, 144531, 144532, 144533, 144534, 144535, 144536, 144647, 144652, 144657, 144658, 144659, 144660, 144661, 144662, 144663, 144664, 144665, 144671, 144672, 144687, 144688, 144689, 144703, 144706, 144707, 144708, 144709, 144710, 144711, 144714, 144715, 144716, 144717, 144718, 144719, 144721, 144724, 144725, 144727, 144730, 144731, 144732, 144734, 144741, 144762, 144770, 144775, 144795, 144796, 144802, 144805, 144807, 144844, 144845, 144857, 144886, 144887, 144894, 144895, 144905, 144908, 144931, 144932, 144933, 144934, 144935, 144936, 144967, 145173, 145174, 145177, 145178, 145179, 145180, 145181, 145305, 145308, 145900, 145927, 145988, 146001, 146036, 146768, 146809, 146830, 146831, 147381, 147824, 148298, 148900, 148911, 148929, 148932, 148933, 148934, 148937, 148938, 148983, 148984, 149006, 149007, 149008, 149011, 149012, 149013, 149015, 149016, 149019, 149020, 149027, 149050, 149081, 149092, 149129, 149145, 149150, 149152, 149399, 149401, 150521, 150522, 150541, 150542, 150566, 150742.\n", " warnings.warn(message)\n", - "/Users/martin/mambaforge/envs/demoland/lib/python3.11/site-packages/libpysal/weights/weights.py:172: UserWarning: The weights matrix is not fully connected: \n", + "/Users/martin/miniforge3/envs/demoland/lib/python3.11/site-packages/libpysal/weights/weights.py:224: UserWarning: The weights matrix is not fully connected: \n", " There are 14 disconnected components.\n", " There are 4 islands with ids: 34428, 68863, 108399, 141475.\n", " warnings.warn(message)\n" @@ -569,9 +556,20 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('WARNING: ', 34428, ' is an island (no neighbors)')\n", + "('WARNING: ', 68863, ' is an island (no neighbors)')\n", + "('WARNING: ', 108399, ' is an island (no neighbors)')\n", + "('WARNING: ', 141475, ' is an island (no neighbors)')\n" + ] + } + ], "source": [ "W.transform = \"r\"\n", "for col in exvars.columns.copy():\n", @@ -588,7 +586,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -610,7 +608,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -629,19 +627,19 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "
HistGradientBoostingRegressor(max_bins=64, max_iter=1000, random_state=0)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" + "
HistGradientBoostingRegressor(max_bins=64, max_iter=1000, random_state=0)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ], "text/plain": [ "HistGradientBoostingRegressor(max_bins=64, max_iter=1000, random_state=0)" ] }, - "execution_count": 32, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -660,7 +658,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -670,9 +668,8 @@ " 16.30293912, 16.42741979, 16.588092 , 16.49096282, 16.6718441 ])" ] }, - "execution_count": 33, "metadata": {}, - "output_type": "execute_result" + "output_type": "display_data" } ], "source": [ @@ -689,12 +686,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ - "with open(f\"{data_folder}/models/air_quality_model_nc_urbanities.pickle\", \"wb\") as f:\n", - " pickle.dump(regressor, f)" + "with open(f\"{data_folder}/models/air_quality_model.joblib\", \"wb\") as f:\n", + " joblib.dump(regressor, f)" ] } ], @@ -714,7 +711,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.0" + "version": "3.11.6" } }, "nbformat": 4, diff --git a/code/02_models/05c_house_price_model_final.ipynb b/code/02_models/05c_house_price_model_final.ipynb index c3bf9a8..91ce452 100644 --- a/code/02_models/05c_house_price_model_final.ipynb +++ b/code/02_models/05c_house_price_model_final.ipynb @@ -14,32 +14,14 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/2f/fhks6w_d0k556plcv3rfmshw0000gn/T/ipykernel_509/1880529722.py:1: UserWarning: Shapely 2.0 is installed, but because PyGEOS is also installed, GeoPandas will still use PyGEOS by default for now. To force to use and test Shapely 2.0, you have to set the environment variable USE_PYGEOS=0. You can do this before starting the Python process, or in your code before importing geopandas:\n", - "\n", - "import os\n", - "os.environ['USE_PYGEOS'] = '0'\n", - "import geopandas\n", - "\n", - "In a future release, GeoPandas will switch to using Shapely by default. If you are using PyGEOS directly (calling PyGEOS functions on geometries from GeoPandas), this will then stop working and you are encouraged to migrate from PyGEOS to Shapely 2.0 (https://shapely.readthedocs.io/en/latest/migration_pygeos.html).\n", - " import geopandas as gpd\n" - ] - } - ], + "outputs": [], "source": [ "import geopandas as gpd\n", "import numpy as np\n", - "import pickle\n", + "import joblib\n", "import libpysal\n", - "import pandas as pd\n", "\n", - "from sklearn.ensemble import HistGradientBoostingRegressor\n", - "from sklearn.metrics import mean_squared_error\n", - "from sklearn.model_selection import cross_val_predict" + "from sklearn.ensemble import HistGradientBoostingRegressor" ] }, { @@ -101,14 +83,16 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "/Users/martin/mambaforge/envs/demoland/lib/python3.11/site-packages/libpysal/weights/weights.py:172: UserWarning: The weights matrix is not fully connected: \n", + "/var/folders/2f/fhks6w_d0k556plcv3rfmshw0000gn/T/ipykernel_49371/1156976480.py:1: FutureWarning: `use_index` defaults to False but will default to True in future. Set True/False directly to control this behavior and silence this warning\n", + " queen = libpysal.weights.Queen.from_dataframe(data)\n", + "/Users/martin/miniforge3/envs/demoland/lib/python3.11/site-packages/libpysal/weights/weights.py:224: UserWarning: The weights matrix is not fully connected: \n", " There are 51 disconnected components.\n", " There are 19 islands with ids: 1676, 2132, 3036, 21306, 33133, 34428, 42635, 42654, 68863, 72800, 74393, 105153, 108399, 134057, 140649, 141143, 141475, 144653, 149708.\n", " warnings.warn(message)\n" @@ -130,7 +114,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -175,7 +159,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -192,7 +176,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -211,19 +195,19 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "
HistGradientBoostingRegressor(max_bins=128, max_iter=1000, random_state=0)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" + "
HistGradientBoostingRegressor(max_bins=128, max_iter=1000, random_state=0)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ], "text/plain": [ "HistGradientBoostingRegressor(max_bins=128, max_iter=1000, random_state=0)" ] }, - "execution_count": 14, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -242,7 +226,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -252,7 +236,7 @@ " 7.7307261 , 7.74621834, 7.5703991 , 7.53491617, 7.4739106 ])" ] }, - "execution_count": 15, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -271,13 +255,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ - "with open(f\"{data_folder}/models/house_price_predictor_england_no_london.pickle\", \"wb\") as f:\n", - " pickle.dump(regressor, f)" + "with open(f\"{data_folder}/models/house_price_model.joblib\", \"wb\") as f:\n", + " joblib.dump(regressor, f)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -296,7 +287,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.0" + "version": "3.11.6" }, "orig_nbformat": 4 },