Skip to content

Instantly share code, notes, and snippets.

@Ziqi-Li
Created June 7, 2021 16:10
Show Gist options
  • Save Ziqi-Li/d280ae85d2d357c091cbd0ed05b58488 to your computer and use it in GitHub Desktop.
Save Ziqi-Li/d280ae85d2d357c091cbd0ed05b58488 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import libpysal as ps\n",
"import geopandas as gp\n",
"import numpy as np\n",
"\n",
"import sys\n",
"sys.path.append('/Users/Ziqi/Desktop/mgwr/')\n",
"from mgwr.gwr import GWR,MGWR \n",
"import matplotlib.pyplot as plt\n",
"from mgwr.sel_bw import Sel_BW "
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"#Load Georgia dataset and generate plot of Georgia counties (figure 1)\n",
"georgia_data = pd.read_csv(ps.examples.get_path('GData_utm.csv'))\n",
"georgia_shp = gp.read_file(ps.examples.get_path('G_utm.shp'))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"#Prepare Georgia dataset inputs\n",
"g_y = georgia_data['PctBach'].values.reshape((-1,1))\n",
"g_X = georgia_data[['PctFB', 'PctBlack', 'PctRural']].values\n",
"u = georgia_data['X']\n",
"v = georgia_data['Y']\n",
"g_coords = list(zip(u,v))\n",
"\n",
"g_X = (g_X - g_X.mean(axis=0)) / g_X.std(axis=0)\n",
"\n",
"g_y = g_y.reshape((-1,1))\n",
"\n",
"g_y = (g_y - g_y.mean(axis=0)) / g_y.std(axis=0)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"117.0\n"
]
}
],
"source": [
"#Calibrate GWR model\n",
"\n",
"gwr_selector = Sel_BW(g_coords, g_y, g_X)\n",
"gwr_bw = gwr_selector.search(bw_min=2)\n",
"print(gwr_bw)\n",
"gwr_results = GWR(g_coords, g_y, g_X, gwr_bw).fit()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<mgwr.gwr.GWRResults at 0x7f8b952dc6d0>"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gwr_results"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"===========================================================================\n",
"Model type Gaussian\n",
"Number of observations: 159\n",
"Number of covariates: 4\n",
"\n",
"Global Regression Results\n",
"---------------------------------------------------------------------------\n",
"Residual sum of squares: 71.793\n",
"Log-likelihood: -162.399\n",
"AIC: 332.798\n",
"AICc: 335.191\n",
"BIC: -713.887\n",
"R2: 0.548\n",
"Adj. R2: 0.540\n",
"\n",
"Variable Est. SE t(Est/SE) p-value\n",
"------------------------------- ---------- ---------- ---------- ----------\n",
"X0 0.000 0.054 0.000 1.000\n",
"X1 0.458 0.066 6.988 0.000\n",
"X2 -0.084 0.055 -1.525 0.127\n",
"X3 -0.374 0.065 -5.734 0.000\n",
"\n",
"Geographically Weighted Regression (GWR) Results\n",
"---------------------------------------------------------------------------\n",
"Spatial kernel: Adaptive bisquare\n",
"Bandwidth used: 117.000\n",
"\n",
"Diagnostic information\n",
"---------------------------------------------------------------------------\n",
"Residual sum of squares: 51.186\n",
"Effective number of parameters (trace(S)): 11.805\n",
"Degree of freedom (n - trace(S)): 147.195\n",
"Sigma estimate: 0.590\n",
"Log-likelihood: -135.503\n",
"AIC: 296.616\n",
"AICc: 299.051\n",
"BIC: 335.913\n",
"R2: 0.678\n",
"Adjusted R2: 0.652\n",
"Adj. alpha (95%): 0.017\n",
"Adj. critical t value (95%): 2.414\n",
"\n",
"Summary Statistics For GWR Parameter Estimates\n",
"---------------------------------------------------------------------------\n",
"Variable Mean STD Min Median Max\n",
"-------------------- ---------- ---------- ---------- ---------- ----------\n",
"X0 -0.004 0.180 -0.296 0.111 0.208\n",
"X1 0.477 0.234 0.123 0.556 0.741\n",
"X2 -0.043 0.083 -0.170 -0.053 0.100\n",
"X3 -0.328 0.060 -0.464 -0.308 -0.241\n",
"===========================================================================\n",
"\n"
]
}
],
"source": [
"gwr_results.summary()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[-0.23204579, 0.22820815, 0.05697445, -0.42649461],\n",
" [-0.2792238 , 0.16511734, 0.09516542, -0.41226348],\n",
" [-0.248944 , 0.20466991, 0.07121197, -0.42573638],\n",
" [-0.23036768, 0.1527493 , 0.0510379 , -0.35938659],\n",
" [ 0.19066196, 0.71627541, -0.16920186, -0.24091753],\n",
" [ 0.1631633 , 0.7217187 , -0.08400431, -0.30053796],\n",
" [ 0.16606586, 0.71709664, -0.09223805, -0.29633022],\n",
" [ 0.12335741, 0.71584149, -0.04894648, -0.26729574],\n",
" [-0.26921578, 0.20975298, 0.09585988, -0.37247221],\n",
" [-0.28700587, 0.15228429, 0.09886708, -0.39369059],\n",
" [ 0.15681417, 0.59890626, -0.16102091, -0.26529282],\n",
" [-0.0675865 , 0.41596721, -0.02876407, -0.31752573],\n",
" [-0.24486047, 0.18238644, 0.0637541 , -0.45146351],\n",
" [-0.29442964, 0.1267327 , 0.09967164, -0.39012506],\n",
" [-0.16288288, 0.27611672, -0.00584834, -0.4429535 ],\n",
" [-0.09585975, 0.36953769, -0.0502692 , -0.40230195],\n",
" [ 0.07974453, 0.59116073, -0.14484444, -0.30787985],\n",
" [ 0.19223428, 0.6796772 , -0.1486328 , -0.26847421],\n",
" [-0.17523465, 0.17925335, 0.01510042, -0.36330729],\n",
" [-0.24334038, 0.17283797, 0.06124296, -0.46097152],\n",
" [-0.10036718, 0.37837812, -0.04326886, -0.38893945],\n",
" [ 0.11409443, 0.67543617, -0.05953219, -0.26023854],\n",
" [ 0.11880665, 0.72362861, -0.03774818, -0.26445896],\n",
" [-0.26140439, 0.15812122, 0.07714826, -0.44811631],\n",
" [-0.15282576, 0.27678627, -0.01545129, -0.44973457],\n",
" [ 0.03019775, 0.33705285, -0.09305741, -0.34304922],\n",
" [ 0.11304399, 0.71577001, -0.03733379, -0.25982377],\n",
" [ 0.13544475, 0.72160747, -0.056585 , -0.27501345],\n",
" [ 0.18522655, 0.71397027, -0.11364616, -0.30804813],\n",
" [-0.13667753, 0.19207024, -0.01005891, -0.37008088],\n",
" [ 0.15070488, 0.68925285, -0.09546872, -0.27429726],\n",
" [-0.28197915, 0.14186479, 0.09412639, -0.42607959],\n",
" [ 0.13228779, 0.70853161, -0.06368225, -0.27195258],\n",
" [-0.27217663, 0.1834351 , 0.09160901, -0.40642427],\n",
" [-0.29157372, 0.13835021, 0.0983081 , -0.3718327 ],\n",
" [ 0.17330802, 0.69053499, -0.16958006, -0.28240648],\n",
" [-0.28961105, 0.13962921, 0.09790866, -0.38886712],\n",
" [ 0.12802202, 0.6610428 , -0.081522 , -0.26509903],\n",
" [ 0.12959892, 0.52950876, -0.14211904, -0.28010866],\n",
" [-0.20646268, 0.22767101, 0.0487464 , -0.34199969],\n",
" [ 0.11241429, 0.72070704, -0.03272004, -0.25920745],\n",
" [ 0.14260517, 0.72352236, -0.0624621 , -0.28251192],\n",
" [-0.25735951, 0.13251162, 0.0686743 , -0.36970318],\n",
" [ 0.15236796, 0.70439723, -0.08734371, -0.28070463],\n",
" [-0.20069901, 0.30426942, 0.05590839, -0.34583091],\n",
" [-0.12170151, 0.29394235, -0.00151217, -0.32401038],\n",
" [-0.22573804, 0.1681668 , 0.05075963, -0.35580153],\n",
" [ 0.12608446, 0.69412433, -0.06532528, -0.26657043],\n",
" [-0.1905817 , 0.1600636 , 0.02292339, -0.36720426],\n",
" [-0.28672233, 0.12913596, 0.0962773 , -0.42376982],\n",
" [-0.10387762, 0.3449763 , -0.04868726, -0.41987077],\n",
" [ 0.18985251, 0.70546289, -0.12514511, -0.31972599],\n",
" [-0.04511962, 0.46073924, -0.07191117, -0.34985834],\n",
" [-0.15483906, 0.30132699, -0.00930108, -0.42249261],\n",
" [ 0.13346174, 0.72869908, -0.04839864, -0.27618159],\n",
" [ 0.14407124, 0.67594735, -0.09499759, -0.26965042],\n",
" [ 0.11349608, 0.71138764, -0.04098198, -0.26013311],\n",
" [ 0.14451605, 0.7188292 , -0.0687953 , -0.28294178],\n",
" [ 0.16928575, 0.71763395, -0.09362275, -0.30786383],\n",
" [ 0.1389996 , 0.70084752, -0.07599473, -0.27300361],\n",
" [ 0.13245737, 0.72653878, -0.04942924, -0.27497052],\n",
" [ 0.17387802, 0.72092513, -0.16729674, -0.25184514],\n",
" [-0.2275241 , 0.19647809, 0.04820579, -0.46362232],\n",
" [ 0.12280109, 0.71997081, -0.04518306, -0.26756677],\n",
" [-0.27912422, 0.12682664, 0.08475635, -0.37158091],\n",
" [ 0.20524371, 0.71866797, -0.15216818, -0.28872866],\n",
" [ 0.15171483, 0.7142168 , -0.07961034, -0.285433 ],\n",
" [ 0.1561952 , 0.72497851, -0.07416205, -0.29739046],\n",
" [ 0.15396195, 0.72259239, -0.07494648, -0.29162096],\n",
" [ 0.20241749, 0.7411108 , -0.16863507, -0.24868452],\n",
" [ 0.11125334, 0.69098384, -0.04877704, -0.25912539],\n",
" [ 0.11129368, 0.49263032, -0.10679333, -0.29876027],\n",
" [ 0.17690495, 0.71144296, -0.10650316, -0.31520883],\n",
" [ 0.11268475, 0.64234741, -0.06783997, -0.2616948 ],\n",
" [ 0.17041469, 0.68490738, -0.11951863, -0.27530607],\n",
" [-0.03764665, 0.39609693, -0.0481946 , -0.30852118],\n",
" [-0.27680459, 0.18733716, 0.09725403, -0.375274 ],\n",
" [ 0.16872317, 0.71919459, -0.09200472, -0.30129357],\n",
" [ 0.19988326, 0.70076237, -0.15087661, -0.27317998],\n",
" [-0.23894638, 0.23617812, 0.06642463, -0.40783456],\n",
" [ 0.12784801, 0.67509107, -0.15454434, -0.26445475],\n",
" [ 0.00784752, 0.51097023, -0.10739752, -0.34000298],\n",
" [ 0.01324256, 0.55631679, -0.09093423, -0.30349313],\n",
" [ 0.19044668, 0.67801239, -0.17044939, -0.25112793],\n",
" [ 0.17506238, 0.62926224, -0.14825535, -0.27121172],\n",
" [-0.28660562, 0.14068159, 0.09680909, -0.40782611],\n",
" [-0.08743882, 0.43724117, -0.02493625, -0.32942076],\n",
" [-0.18842721, 0.20057302, 0.02900389, -0.35020663],\n",
" [-0.1857625 , 0.25196748, 0.01251416, -0.44881596],\n",
" [ 0.20143713, 0.70265244, -0.1613357 , -0.3028506 ],\n",
" [-0.2058501 , 0.23241684, 0.03026423, -0.45137574],\n",
" [-0.29053062, 0.13047888, 0.09852899, -0.40719599],\n",
" [ 0.14451405, 0.72736741, -0.0602901 , -0.28464588],\n",
" [ 0.19004365, 0.71462712, -0.16904179, -0.27232054],\n",
" [-0.20814289, 0.22095639, 0.03144733, -0.46059811],\n",
" [ 0.00082393, 0.37664513, -0.07382611, -0.31159298],\n",
" [ 0.1795405 , 0.71353792, -0.10820381, -0.31108131],\n",
" [ 0.03668795, 0.36387564, -0.09524137, -0.3273337 ],\n",
" [ 0.14017135, 0.600748 , -0.11079426, -0.27188809],\n",
" [-0.22705923, 0.14116941, 0.04613618, -0.36342958],\n",
" [-0.26418043, 0.14107847, 0.07536233, -0.36536709],\n",
" [ 0.18253082, 0.64189181, -0.16026664, -0.26576157],\n",
" [-0.18235844, 0.30162477, 0.02022086, -0.39249068],\n",
" [ 0.20679194, 0.71604752, -0.14566821, -0.28934532],\n",
" [ 0.12764087, 0.72848948, -0.04231594, -0.27011484],\n",
" [ 0.07345292, 0.40182254, -0.10494564, -0.32653241],\n",
" [ 0.18110408, 0.70326498, -0.11982898, -0.28809906],\n",
" [ 0.19199708, 0.71330395, -0.12181188, -0.30711325],\n",
" [ 0.19841406, 0.7089675 , -0.13529096, -0.31261915],\n",
" [ 0.12159739, 0.70749795, -0.05333524, -0.26444676],\n",
" [ 0.07117067, 0.47856388, -0.1123748 , -0.29065921],\n",
" [ 0.13438646, 0.72407912, -0.05328659, -0.27513557],\n",
" [-0.24754362, 0.19027828, 0.06743225, -0.44001573],\n",
" [ 0.16107555, 0.62082885, -0.13193559, -0.27231156],\n",
" [ 0.11342935, 0.7025378 , -0.04568176, -0.26044226],\n",
" [-0.17263832, 0.30453836, 0.03875095, -0.33079797],\n",
" [ 0.20834847, 0.72291477, -0.16344948, -0.26382393],\n",
" [-0.07591665, 0.22280374, -0.04615558, -0.36782772],\n",
" [ 0.15313888, 0.7259677 , -0.07060643, -0.29641182],\n",
" [-0.1103036 , 0.21239354, -0.02519001, -0.36279136],\n",
" [ 0.13974068, 0.66130106, -0.16502354, -0.2831834 ],\n",
" [ 0.16608448, 0.70468321, -0.10143272, -0.28586956],\n",
" [-0.02241416, 0.31760267, -0.06696405, -0.3313108 ],\n",
" [-0.01230871, 0.46381389, -0.10419571, -0.36433727],\n",
" [-0.24282594, 0.12927797, 0.05595741, -0.36612566],\n",
" [ 0.16864795, 0.66355845, -0.12800839, -0.27106081],\n",
" [ 0.16431191, 0.71992475, -0.08694075, -0.30495974],\n",
" [-0.02613713, 0.2725321 , -0.07018936, -0.35661879],\n",
" [-0.09476494, 0.2667752 , -0.02709326, -0.34030372],\n",
" [ 0.12584005, 0.50856804, -0.1247695 , -0.28724611],\n",
" [ 0.20643284, 0.7273282 , -0.16346935, -0.27596993],\n",
" [-0.17968579, 0.28056404, 0.01107182, -0.42238967],\n",
" [ 0.09583397, 0.46713153, -0.119792 , -0.29256208],\n",
" [-0.24984063, 0.23674969, 0.08095965, -0.38047793],\n",
" [-0.14149158, 0.21122113, -0.00375682, -0.35528427],\n",
" [-0.2959267 , 0.12320249, 0.09884201, -0.37693286],\n",
" [-0.28230516, 0.16313483, 0.0960423 , -0.37100554],\n",
" [-0.17386626, 0.2992096 , 0.01011241, -0.40617253],\n",
" [ 0.14653202, 0.72908939, -0.06113222, -0.28918771],\n",
" [-0.11336121, 0.39026461, -0.02434529, -0.36231522],\n",
" [ 0.11766981, 0.5963948 , -0.08513572, -0.26878783],\n",
" [-0.25744048, 0.19145098, 0.08125192, -0.35479657],\n",
" [ 0.09865195, 0.58240786, -0.12768002, -0.27053748],\n",
" [ 0.14306255, 0.72913304, -0.05744139, -0.28472151],\n",
" [ 0.15264367, 0.56041663, -0.14049909, -0.27787166],\n",
" [ 0.11602845, 0.72176754, -0.03625398, -0.26178557],\n",
" [ 0.17458385, 0.71130353, -0.10622249, -0.29449009],\n",
" [-0.26521209, 0.16001795, 0.08068927, -0.43755559],\n",
" [ 0.19197698, 0.72997737, -0.16924107, -0.25676804],\n",
" [ 0.12212028, 0.68696698, -0.14181048, -0.25266057],\n",
" [-0.22854044, 0.20841072, 0.05048507, -0.45073821],\n",
" [-0.07228922, 0.25469697, -0.0442055 , -0.35237852],\n",
" [-0.20808154, 0.28658789, 0.04504185, -0.37900132],\n",
" [ 0.15018614, 0.72727365, -0.06624495, -0.290973 ],\n",
" [ 0.12224789, 0.72537151, -0.03999712, -0.26669492],\n",
" [-0.24433268, 0.23557256, 0.0818788 , -0.34820656],\n",
" [ 0.20530293, 0.7077298 , -0.15296797, -0.30733713],\n",
" [ 0.13180853, 0.67288348, -0.1401622 , -0.24886494],\n",
" [-0.27323956, 0.15841475, 0.08679362, -0.35949224]])"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gwr_results.params"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0.07509112, 0.11169745, 0.08762431, 0.08084088],\n",
" [0.07416411, 0.09015736, 0.08542296, 0.07642656],\n",
" [0.07431592, 0.10413589, 0.08620805, 0.07896894],\n",
" [0.07881429, 0.08303251, 0.09238536, 0.08318373],\n",
" [0.06863529, 0.08462591, 0.07523223, 0.08805308],\n",
" [0.06627771, 0.08411544, 0.06027979, 0.08485987],\n",
" [0.06494176, 0.08257096, 0.05952952, 0.08312364],\n",
" [0.06488039, 0.08073815, 0.05876445, 0.08477988],\n",
" [0.07477806, 0.09212329, 0.08369522, 0.07746658],\n",
" [0.07414499, 0.08347262, 0.08486607, 0.07543555],\n",
" [0.0755054 , 0.08466333, 0.07789316, 0.09043235],\n",
" [0.08126771, 0.09744847, 0.08931803, 0.08943042],\n",
" [0.07539323, 0.10424688, 0.08945662, 0.08149242],\n",
" [0.07571931, 0.08239705, 0.08776559, 0.07716609],\n",
" [0.07737881, 0.11979828, 0.09234914, 0.08675711],\n",
" [0.07555377, 0.11634755, 0.0889253 , 0.08622775],\n",
" [0.07191035, 0.10101888, 0.08373136, 0.089161 ],\n",
" [0.06893742, 0.08639408, 0.06565042, 0.090001 ],\n",
" [0.07660869, 0.08142174, 0.08953211, 0.08289807],\n",
" [0.0759326 , 0.10379647, 0.09080543, 0.08267039],\n",
" [0.07525379, 0.11558556, 0.08820447, 0.08518623],\n",
" [0.06704382, 0.07940666, 0.05945872, 0.08406642],\n",
" [0.06530151, 0.08283018, 0.05971893, 0.08775246],\n",
" [0.07499102, 0.09604638, 0.08842064, 0.07970395],\n",
" [0.07844984, 0.12155822, 0.09402281, 0.08888748],\n",
" [0.07484806, 0.08074294, 0.07999515, 0.08453662],\n",
" [0.06572488, 0.0816634 , 0.05957179, 0.08696279],\n",
" [0.06518211, 0.08147342, 0.05910363, 0.08459444],\n",
" [0.06658828, 0.08564547, 0.06190488, 0.08587082],\n",
" [0.07557722, 0.08116582, 0.08779471, 0.08365301],\n",
" [0.06565114, 0.08073566, 0.05964227, 0.08387844],\n",
" [0.07463244, 0.08761933, 0.08672934, 0.0768548 ],\n",
" [0.06447788, 0.07954806, 0.05818598, 0.08268757],\n",
" [0.07381984, 0.09300701, 0.08437232, 0.07640651],\n",
" [0.07708338, 0.08256359, 0.08946201, 0.07915643],\n",
" [0.06955559, 0.09008944, 0.07555668, 0.09056153],\n",
" [0.07467928, 0.08190098, 0.08598516, 0.0760287 ],\n",
" [0.06775391, 0.08090471, 0.06074683, 0.08548358],\n",
" [0.07527997, 0.08462124, 0.07559956, 0.0878988 ],\n",
" [0.07718282, 0.08353458, 0.0874375 , 0.08009685],\n",
" [0.06582555, 0.08285712, 0.06006677, 0.08853485],\n",
" [0.06482307, 0.08196423, 0.05894651, 0.0841175 ],\n",
" [0.07789416, 0.08400643, 0.09137025, 0.08269681],\n",
" [0.06427222, 0.0800888 , 0.05845001, 0.08209534],\n",
" [0.08101367, 0.10932893, 0.08887421, 0.08688172],\n",
" [0.07982309, 0.08774212, 0.08825648, 0.08342701],\n",
" [0.07781921, 0.08179878, 0.09088018, 0.08172938],\n",
" [0.06533831, 0.07902107, 0.05849553, 0.08283456],\n",
" [0.07779847, 0.08313885, 0.09108656, 0.08439552],\n",
" [0.0748991 , 0.08506911, 0.08694722, 0.07653213],\n",
" [0.07674081, 0.11856509, 0.09065342, 0.08793437],\n",
" [0.06838294, 0.08798876, 0.06439485, 0.08878653],\n",
" [0.07483004, 0.11289694, 0.08744413, 0.08691298],\n",
" [0.0764746 , 0.11838345, 0.09026645, 0.08503173],\n",
" [0.0655827 , 0.0834424 , 0.05984213, 0.08682856],\n",
" [0.06699509, 0.08135534, 0.06070302, 0.08542863],\n",
" [0.06573498, 0.08086436, 0.05928917, 0.08592576],\n",
" [0.06411971, 0.08088754, 0.05835294, 0.08271683],\n",
" [0.06680816, 0.08505291, 0.06108985, 0.0855264 ],\n",
" [0.06494366, 0.07956845, 0.058562 , 0.0826073 ],\n",
" [0.06527532, 0.08275155, 0.05950887, 0.08615789],\n",
" [0.06969009, 0.09127551, 0.07947599, 0.09168721],\n",
" [0.07740766, 0.11413535, 0.09392242, 0.08573262],\n",
" [0.0647986 , 0.08154746, 0.05897019, 0.08572062],\n",
" [0.07784487, 0.08369033, 0.09108163, 0.08132537],\n",
" [0.06681071, 0.08693436, 0.0668799 , 0.08736455],\n",
" [0.06394079, 0.08050584, 0.0582732 , 0.08191866],\n",
" [0.06664369, 0.08448717, 0.06039002, 0.08567295],\n",
" [0.06518837, 0.08259572, 0.05931151, 0.08377169],\n",
" [0.06850604, 0.08804357, 0.0749754 , 0.08975091],\n",
" [0.06592804, 0.07909966, 0.05866331, 0.08378425],\n",
" [0.0745143 , 0.08576682, 0.07230505, 0.08901723],\n",
" [0.06752444, 0.08626043, 0.06235761, 0.08674507],\n",
" [0.06889233, 0.08127805, 0.06129172, 0.08608084],\n",
" [0.06688427, 0.08355855, 0.06186584, 0.08675777],\n",
" [0.07968286, 0.08898558, 0.0850476 , 0.08641231],\n",
" [0.07436776, 0.08668704, 0.08389115, 0.07640501],\n",
" [0.06594732, 0.08388114, 0.06025884, 0.08439563],\n",
" [0.06655619, 0.08497304, 0.06477864, 0.08679308],\n",
" [0.07458027, 0.10907868, 0.08543774, 0.07946655],\n",
" [0.07111287, 0.09632111, 0.08332114, 0.09160481],\n",
" [0.07328861, 0.10815041, 0.08600784, 0.08773282],\n",
" [0.07475101, 0.10744143, 0.08751073, 0.09019768],\n",
" [0.06927413, 0.08313111, 0.07203268, 0.08752444],\n",
" [0.069757 , 0.08442614, 0.06653858, 0.08871839],\n",
" [0.07413711, 0.08368534, 0.08526921, 0.0753668 ],\n",
" [0.07800832, 0.11085309, 0.08882675, 0.08949015],\n",
" [0.07682286, 0.08068875, 0.08896292, 0.08089781],\n",
" [0.07757469, 0.11981104, 0.09295742, 0.08640549],\n",
" [0.07132828, 0.0915927 , 0.07191343, 0.09387914],\n",
" [0.07721188, 0.1184146 , 0.0926148 , 0.08548682],\n",
" [0.07470324, 0.08301275, 0.08625569, 0.07579766],\n",
" [0.06577571, 0.08323727, 0.05970712, 0.08546955],\n",
" [0.06976994, 0.09026924, 0.07539247, 0.09178506],\n",
" [0.07782082, 0.1186818 , 0.09415184, 0.08671301],\n",
" [0.07740599, 0.08481101, 0.08289651, 0.08440745],\n",
" [0.06671936, 0.08552636, 0.06182492, 0.08578566],\n",
" [0.07552437, 0.08207514, 0.08045663, 0.08449799],\n",
" [0.07171369, 0.08586567, 0.06655706, 0.09049245],\n",
" [0.0798021 , 0.08457166, 0.09355233, 0.08495792],\n",
" [0.0774958 , 0.08272335, 0.0906678 , 0.08123277],\n",
" [0.06851053, 0.08245991, 0.06733121, 0.08647006],\n",
" [0.07470498, 0.11254099, 0.0857698 , 0.08166253],\n",
" [0.06736034, 0.0875697 , 0.06512299, 0.08808302],\n",
" [0.06603331, 0.08345256, 0.06029148, 0.08777296],\n",
" [0.07464118, 0.08236054, 0.07643563, 0.08591116],\n",
" [0.06499956, 0.08308727, 0.06073483, 0.08418509],\n",
" [0.06690389, 0.086441 , 0.0626459 , 0.0866899 ],\n",
" [0.06784974, 0.08805879, 0.06501815, 0.08858807],\n",
" [0.06575344, 0.07999595, 0.05907337, 0.08429979],\n",
" [0.07783711, 0.08551789, 0.08048462, 0.0876428 ],\n",
" [0.06525189, 0.08202532, 0.0592885 , 0.08525762],\n",
" [0.07464787, 0.1030873 , 0.08752765, 0.07986978],\n",
" [0.07050581, 0.08524737, 0.06612198, 0.08983282],\n",
" [0.06540587, 0.0796849 , 0.05862459, 0.08437253],\n",
" [0.081219 , 0.09894778, 0.08881588, 0.0852131 ],\n",
" [0.06712126, 0.08586249, 0.06895161, 0.08734064],\n",
" [0.07597883, 0.08087442, 0.08655306, 0.08460189],\n",
" [0.06682988, 0.08481359, 0.06055074, 0.08617514],\n",
" [0.07617182, 0.08057819, 0.0878848 , 0.08346133],\n",
" [0.06952724, 0.09224351, 0.07893956, 0.08927303],\n",
" [0.06446503, 0.08133911, 0.05921371, 0.08275141],\n",
" [0.07664363, 0.08174987, 0.08429243, 0.08325907],\n",
" [0.07637651, 0.11543844, 0.08886367, 0.09000653],\n",
" [0.08038156, 0.08577121, 0.09413066, 0.08556581],\n",
" [0.06878554, 0.08489274, 0.06403432, 0.08924908],\n",
" [0.06673774, 0.08481978, 0.06080313, 0.08544658],\n",
" [0.07548204, 0.08020933, 0.0839511 , 0.08409529],\n",
" [0.07619513, 0.08033455, 0.0861439 , 0.0815169 ],\n",
" [0.07403176, 0.0858923 , 0.07281039, 0.08804069],\n",
" [0.06870638, 0.08888198, 0.07178981, 0.09021427],\n",
" [0.07605672, 0.11724289, 0.08941857, 0.08360921],\n",
" [0.07584557, 0.0857872 , 0.07720305, 0.08699438],\n",
" [0.0742608 , 0.1006494 , 0.08281946, 0.07817975],\n",
" [0.07622829, 0.08016314, 0.08827675, 0.08197338],\n",
" [0.07788169, 0.08358635, 0.0908015 , 0.08015026],\n",
" [0.07510205, 0.08227986, 0.08591453, 0.07696384],\n",
" [0.07491888, 0.11445234, 0.08710846, 0.08217941],\n",
" [0.0665839 , 0.08456508, 0.06037482, 0.08659989],\n",
" [0.07585039, 0.11457318, 0.08751099, 0.08549692],\n",
" [0.07216076, 0.08575649, 0.06586844, 0.09047428],\n",
" [0.07597459, 0.08284505, 0.08646684, 0.07840758],\n",
" [0.07321234, 0.08249019, 0.07924822, 0.08675189],\n",
" [0.06611376, 0.08392473, 0.06005104, 0.0863158 ],\n",
" [0.07318495, 0.08566128, 0.07067742, 0.089058 ],\n",
" [0.06577741, 0.08263711, 0.05997688, 0.08792505],\n",
" [0.06474275, 0.08265342, 0.05992056, 0.08320474],\n",
" [0.07419457, 0.0930495 , 0.08639505, 0.07782933],\n",
" [0.0694689 , 0.09017544, 0.07676546, 0.09170196],\n",
" [0.07229129, 0.09670639, 0.08503677, 0.09262393],\n",
" [0.07631365, 0.11301323, 0.09117862, 0.08354533],\n",
" [0.07545811, 0.07966383, 0.08564139, 0.08250823],\n",
" [0.07572909, 0.11139242, 0.08532273, 0.08216544],\n",
" [0.06629115, 0.08399748, 0.06007774, 0.08569077],\n",
" [0.06554297, 0.08295969, 0.05989925, 0.08762616],\n",
" [0.07710598, 0.09126364, 0.0856913 , 0.08006184],\n",
" [0.06970041, 0.09015304, 0.06902599, 0.09168545],\n",
" [0.07387119, 0.08956631, 0.08406852, 0.09139677],\n",
" [0.07756448, 0.08230312, 0.08983603, 0.07989109]])"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gwr_results.bse"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"x_names = [\"Intercept\"] + ['PctFB', 'PctBlack', 'PctRural']"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
"rslt_df = pd.DataFrame(np.hstack([georgia_data.AreaKey.values.reshape(-1,1),\n",
" gwr_results.params, \n",
" gwr_results.bse]))\n",
"\n",
"rslt_df.columns = [\"ID\"] + [\"param_\" + x for x in x_names] + [\"bse_\" + x for x in x_names]"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>ID</th>\n",
" <th>param_Intercept</th>\n",
" <th>param_PctFB</th>\n",
" <th>param_PctBlack</th>\n",
" <th>param_PctRural</th>\n",
" <th>bse_Intercept</th>\n",
" <th>bse_PctFB</th>\n",
" <th>bse_PctBlack</th>\n",
" <th>bse_PctRural</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>13001.0</td>\n",
" <td>-0.232046</td>\n",
" <td>0.228208</td>\n",
" <td>0.056974</td>\n",
" <td>-0.426495</td>\n",
" <td>0.075091</td>\n",
" <td>0.111697</td>\n",
" <td>0.087624</td>\n",
" <td>0.080841</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>13003.0</td>\n",
" <td>-0.279224</td>\n",
" <td>0.165117</td>\n",
" <td>0.095165</td>\n",
" <td>-0.412263</td>\n",
" <td>0.074164</td>\n",
" <td>0.090157</td>\n",
" <td>0.085423</td>\n",
" <td>0.076427</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>13005.0</td>\n",
" <td>-0.248944</td>\n",
" <td>0.204670</td>\n",
" <td>0.071212</td>\n",
" <td>-0.425736</td>\n",
" <td>0.074316</td>\n",
" <td>0.104136</td>\n",
" <td>0.086208</td>\n",
" <td>0.078969</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>13007.0</td>\n",
" <td>-0.230368</td>\n",
" <td>0.152749</td>\n",
" <td>0.051038</td>\n",
" <td>-0.359387</td>\n",
" <td>0.078814</td>\n",
" <td>0.083033</td>\n",
" <td>0.092385</td>\n",
" <td>0.083184</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>13009.0</td>\n",
" <td>0.190662</td>\n",
" <td>0.716275</td>\n",
" <td>-0.169202</td>\n",
" <td>-0.240918</td>\n",
" <td>0.068635</td>\n",
" <td>0.084626</td>\n",
" <td>0.075232</td>\n",
" <td>0.088053</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" ID param_Intercept param_PctFB param_PctBlack param_PctRural \\\n",
"0 13001.0 -0.232046 0.228208 0.056974 -0.426495 \n",
"1 13003.0 -0.279224 0.165117 0.095165 -0.412263 \n",
"2 13005.0 -0.248944 0.204670 0.071212 -0.425736 \n",
"3 13007.0 -0.230368 0.152749 0.051038 -0.359387 \n",
"4 13009.0 0.190662 0.716275 -0.169202 -0.240918 \n",
"\n",
" bse_Intercept bse_PctFB bse_PctBlack bse_PctRural \n",
"0 0.075091 0.111697 0.087624 0.080841 \n",
"1 0.074164 0.090157 0.085423 0.076427 \n",
"2 0.074316 0.104136 0.086208 0.078969 \n",
"3 0.078814 0.083033 0.092385 0.083184 \n",
"4 0.068635 0.084626 0.075232 0.088053 "
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rslt_df.head()"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
"rslt_df.to_csv(\"mgwr_rslt.csv\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment