Skip to content

Commit 3c6db2f

Browse files
committed
clean and rerun notebooks
1 parent ff71b1c commit 3c6db2f

File tree

3 files changed

+238
-73
lines changed

3 files changed

+238
-73
lines changed

notebooks/Binomial_GLM.ipynb

Lines changed: 75 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,41 @@
33
{
44
"cell_type": "code",
55
"execution_count": 1,
6-
"metadata": {},
6+
"metadata": {
7+
"execution": {
8+
"iopub.execute_input": "2023-10-14T01:22:52.996793Z",
9+
"iopub.status.busy": "2023-10-14T01:22:52.996204Z",
10+
"iopub.status.idle": "2023-10-14T01:22:54.292332Z",
11+
"shell.execute_reply": "2023-10-14T01:22:54.291240Z",
12+
"shell.execute_reply.started": "2023-10-14T01:22:52.996686Z"
13+
}
14+
},
715
"outputs": [],
816
"source": [
917
"from spglm.glm import GLM\n",
1018
"from spglm.family import Binomial\n",
11-
"import libpysal.api as ps\n",
12-
"import numpy as np"
19+
"import numpy"
1320
]
1421
},
1522
{
1623
"cell_type": "code",
1724
"execution_count": 2,
18-
"metadata": {},
25+
"metadata": {
26+
"execution": {
27+
"iopub.execute_input": "2023-10-14T01:22:54.296350Z",
28+
"iopub.status.busy": "2023-10-14T01:22:54.295680Z",
29+
"iopub.status.idle": "2023-10-14T01:22:54.316200Z",
30+
"shell.execute_reply": "2023-10-14T01:22:54.314911Z",
31+
"shell.execute_reply.started": "2023-10-14T01:22:54.296296Z"
32+
}
33+
},
1934
"outputs": [],
2035
"source": [
2136
"# Load sample dataset - Subset of london house price dataset\n",
22-
"db = ps.open(ps.get_path(\"columbus.dbf\"), \"r\")\n",
37+
"#db = ps.open(ps.get_path(\"columbus.dbf\"), \"r\")\n",
2338
"\n",
2439
"#Set dependent variable\n",
25-
"y = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,\n",
40+
"y = numpy.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,\n",
2641
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0,\n",
2742
" 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,\n",
2843
" 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
@@ -39,7 +54,7 @@
3954
"y = y.reshape((316,1))\n",
4055
"\n",
4156
"#Set independent variable (FLOORSZ)\n",
42-
"X = np.array([ 77, 75, 64, 95, 107, 100, 81, 151, 98, 260, 171, 161, 91,\n",
57+
"X = numpy.array([ 77, 75, 64, 95, 107, 100, 81, 151, 98, 260, 171, 161, 91,\n",
4358
" 80, 50, 85, 52, 69, 60, 84, 155, 97, 69, 126, 90, 43,\n",
4459
" 51, 41, 140, 80, 52, 86, 66, 60, 40, 155, 138, 97, 115,\n",
4560
" 148, 206, 60, 53, 96, 88, 160, 31, 43, 154, 60, 131, 60,\n",
@@ -70,15 +85,22 @@
7085
{
7186
"cell_type": "code",
7287
"execution_count": 3,
73-
"metadata": {},
88+
"metadata": {
89+
"execution": {
90+
"iopub.execute_input": "2023-10-14T01:22:54.317859Z",
91+
"iopub.status.busy": "2023-10-14T01:22:54.317442Z",
92+
"iopub.status.idle": "2023-10-14T01:22:54.328544Z",
93+
"shell.execute_reply": "2023-10-14T01:22:54.327834Z",
94+
"shell.execute_reply.started": "2023-10-14T01:22:54.317826Z"
95+
}
96+
},
7497
"outputs": [],
7598
"source": [
7699
"# Estimate Binomial GLM\n",
77100
"\n",
78101
"# First instantiate a GLM model object\n",
79-
"model = GLM(\n",
80-
" y, X, family=Binomial()\n",
81-
") # Set family to Binomial family object for Binomial GLM\n",
102+
"# -- Set family to Binomial family object for Binomial GLM\n",
103+
"model = GLM(y, X, family=Binomial()) \n",
82104
"\n",
83105
"# Then use the fit method to estimate coefficients and compute diagnostics\n",
84106
"results = model.fit()"
@@ -87,7 +109,15 @@
87109
{
88110
"cell_type": "code",
89111
"execution_count": 4,
90-
"metadata": {},
112+
"metadata": {
113+
"execution": {
114+
"iopub.execute_input": "2023-10-14T01:22:54.330385Z",
115+
"iopub.status.busy": "2023-10-14T01:22:54.329865Z",
116+
"iopub.status.idle": "2023-10-14T01:22:54.335674Z",
117+
"shell.execute_reply": "2023-10-14T01:22:54.334451Z",
118+
"shell.execute_reply.started": "2023-10-14T01:22:54.330362Z"
119+
}
120+
},
91121
"outputs": [
92122
{
93123
"name": "stdout",
@@ -105,7 +135,15 @@
105135
{
106136
"cell_type": "code",
107137
"execution_count": 5,
108-
"metadata": {},
138+
"metadata": {
139+
"execution": {
140+
"iopub.execute_input": "2023-10-14T01:22:54.337573Z",
141+
"iopub.status.busy": "2023-10-14T01:22:54.337242Z",
142+
"iopub.status.idle": "2023-10-14T01:22:54.342482Z",
143+
"shell.execute_reply": "2023-10-14T01:22:54.341622Z",
144+
"shell.execute_reply.started": "2023-10-14T01:22:54.337545Z"
145+
}
146+
},
109147
"outputs": [
110148
{
111149
"name": "stdout",
@@ -123,7 +161,15 @@
123161
{
124162
"cell_type": "code",
125163
"execution_count": 6,
126-
"metadata": {},
164+
"metadata": {
165+
"execution": {
166+
"iopub.execute_input": "2023-10-14T01:22:54.344204Z",
167+
"iopub.status.busy": "2023-10-14T01:22:54.343721Z",
168+
"iopub.status.idle": "2023-10-14T01:22:54.349208Z",
169+
"shell.execute_reply": "2023-10-14T01:22:54.348295Z",
170+
"shell.execute_reply.started": "2023-10-14T01:22:54.344177Z"
171+
}
172+
},
127173
"outputs": [
128174
{
129175
"name": "stdout",
@@ -141,13 +187,21 @@
141187
{
142188
"cell_type": "code",
143189
"execution_count": 7,
144-
"metadata": {},
190+
"metadata": {
191+
"execution": {
192+
"iopub.execute_input": "2023-10-14T01:22:54.354033Z",
193+
"iopub.status.busy": "2023-10-14T01:22:54.353469Z",
194+
"iopub.status.idle": "2023-10-14T01:22:54.358243Z",
195+
"shell.execute_reply": "2023-10-14T01:22:54.356998Z",
196+
"shell.execute_reply.started": "2023-10-14T01:22:54.354007Z"
197+
}
198+
},
145199
"outputs": [
146200
{
147201
"name": "stdout",
148202
"output_type": "stream",
149203
"text": [
150-
"155.19347530342466\n"
204+
"155.1934753034247\n"
151205
]
152206
}
153207
],
@@ -160,21 +214,21 @@
160214
"metadata": {
161215
"anaconda-cloud": {},
162216
"kernelspec": {
163-
"display_name": "Python [Root]",
217+
"display_name": "Python [conda env:py311_spglm]",
164218
"language": "python",
165-
"name": "Python [Root]"
219+
"name": "conda-env-py311_spglm-py"
166220
},
167221
"language_info": {
168222
"codemirror_mode": {
169223
"name": "ipython",
170-
"version": 2
224+
"version": 3
171225
},
172226
"file_extension": ".py",
173227
"mimetype": "text/x-python",
174228
"name": "python",
175229
"nbconvert_exporter": "python",
176-
"pygments_lexer": "ipython2",
177-
"version": "2.7.12"
230+
"pygments_lexer": "ipython3",
231+
"version": "3.11.6"
178232
}
179233
},
180234
"nbformat": 4,

notebooks/Gaussian_GLM.ipynb

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,69 @@
33
{
44
"cell_type": "code",
55
"execution_count": 1,
6-
"metadata": {},
6+
"metadata": {
7+
"execution": {
8+
"iopub.execute_input": "2023-10-14T01:23:49.094651Z",
9+
"iopub.status.busy": "2023-10-14T01:23:49.094291Z",
10+
"iopub.status.idle": "2023-10-14T01:23:50.283296Z",
11+
"shell.execute_reply": "2023-10-14T01:23:50.282506Z",
12+
"shell.execute_reply.started": "2023-10-14T01:23:49.094628Z"
13+
}
14+
},
715
"outputs": [],
816
"source": [
917
"from spglm.glm import GLM\n",
10-
"import libpysal.api as ps\n",
11-
"import numpy as np"
18+
"import libpysal\n",
19+
"import numpy"
1220
]
1321
},
1422
{
1523
"cell_type": "code",
1624
"execution_count": 2,
17-
"metadata": {},
25+
"metadata": {
26+
"execution": {
27+
"iopub.execute_input": "2023-10-14T01:23:50.947534Z",
28+
"iopub.status.busy": "2023-10-14T01:23:50.946850Z",
29+
"iopub.status.idle": "2023-10-14T01:23:50.956114Z",
30+
"shell.execute_reply": "2023-10-14T01:23:50.954841Z",
31+
"shell.execute_reply.started": "2023-10-14T01:23:50.947502Z"
32+
}
33+
},
1834
"outputs": [],
1935
"source": [
2036
"# Load sample dataset - columbus dataset\n",
21-
"db = ps.open(ps.get_path(\"columbus.dbf\"), \"r\")\n",
37+
"db = libpysal.io.open(libpysal.examples.get_path(\"columbus.dbf\"))\n",
2238
"\n",
2339
"# Set dependent variable\n",
24-
"y = np.array(db.by_col(\"HOVAL\"))\n",
25-
"y = np.reshape(y, (49, 1))\n",
40+
"y = numpy.array(db.by_col(\"HOVAL\"))\n",
41+
"y = numpy.reshape(y, (49, 1))\n",
2642
"\n",
2743
"# Set indepdent varibLES\n",
2844
"X = []\n",
2945
"X.append(db.by_col(\"INC\"))\n",
3046
"X.append(db.by_col(\"CRIME\"))\n",
31-
"X = np.array(X).T"
47+
"X = numpy.array(X).T"
3248
]
3349
},
3450
{
3551
"cell_type": "code",
3652
"execution_count": 3,
37-
"metadata": {},
53+
"metadata": {
54+
"execution": {
55+
"iopub.execute_input": "2023-10-14T01:23:52.355767Z",
56+
"iopub.status.busy": "2023-10-14T01:23:52.355010Z",
57+
"iopub.status.idle": "2023-10-14T01:23:52.367917Z",
58+
"shell.execute_reply": "2023-10-14T01:23:52.366305Z",
59+
"shell.execute_reply.started": "2023-10-14T01:23:52.355719Z"
60+
}
61+
},
3862
"outputs": [],
3963
"source": [
4064
"# Estimate Gaussian GLM\n",
4165
"\n",
4266
"# First instantiate a GLM model object\n",
43-
"model = GLM(\n",
44-
" y, X\n",
45-
") # Gaussian is the default family parameter so it doesn't need to be set\n",
67+
"# -- Gaussian is the default family parameter so it doesn't need to be set\n",
68+
"model = GLM(y, X) \n",
4669
"\n",
4770
"# Then use the fit method to estimate coefficients and compute diagnostics\n",
4871
"results = model.fit()"
@@ -51,7 +74,15 @@
5174
{
5275
"cell_type": "code",
5376
"execution_count": 4,
54-
"metadata": {},
77+
"metadata": {
78+
"execution": {
79+
"iopub.execute_input": "2023-10-14T01:23:53.261041Z",
80+
"iopub.status.busy": "2023-10-14T01:23:53.260511Z",
81+
"iopub.status.idle": "2023-10-14T01:23:53.267351Z",
82+
"shell.execute_reply": "2023-10-14T01:23:53.266163Z",
83+
"shell.execute_reply.started": "2023-10-14T01:23:53.261004Z"
84+
}
85+
},
5586
"outputs": [
5687
{
5788
"name": "stdout",
@@ -69,7 +100,15 @@
69100
{
70101
"cell_type": "code",
71102
"execution_count": 5,
72-
"metadata": {},
103+
"metadata": {
104+
"execution": {
105+
"iopub.execute_input": "2023-10-14T01:23:54.091698Z",
106+
"iopub.status.busy": "2023-10-14T01:23:54.091257Z",
107+
"iopub.status.idle": "2023-10-14T01:23:54.097334Z",
108+
"shell.execute_reply": "2023-10-14T01:23:54.096406Z",
109+
"shell.execute_reply.started": "2023-10-14T01:23:54.091672Z"
110+
}
111+
},
73112
"outputs": [
74113
{
75114
"name": "stdout",
@@ -87,7 +126,15 @@
87126
{
88127
"cell_type": "code",
89128
"execution_count": 6,
90-
"metadata": {},
129+
"metadata": {
130+
"execution": {
131+
"iopub.execute_input": "2023-10-14T01:23:55.947271Z",
132+
"iopub.status.busy": "2023-10-14T01:23:55.946980Z",
133+
"iopub.status.idle": "2023-10-14T01:23:55.952002Z",
134+
"shell.execute_reply": "2023-10-14T01:23:55.950887Z",
135+
"shell.execute_reply.started": "2023-10-14T01:23:55.947249Z"
136+
}
137+
},
91138
"outputs": [
92139
{
93140
"name": "stdout",
@@ -105,7 +152,15 @@
105152
{
106153
"cell_type": "code",
107154
"execution_count": 7,
108-
"metadata": {},
155+
"metadata": {
156+
"execution": {
157+
"iopub.execute_input": "2023-10-14T01:23:57.273553Z",
158+
"iopub.status.busy": "2023-10-14T01:23:57.273234Z",
159+
"iopub.status.idle": "2023-10-14T01:23:57.278805Z",
160+
"shell.execute_reply": "2023-10-14T01:23:57.277856Z",
161+
"shell.execute_reply.started": "2023-10-14T01:23:57.273534Z"
162+
}
163+
},
109164
"outputs": [
110165
{
111166
"name": "stdout",
@@ -123,23 +178,23 @@
123178
],
124179
"metadata": {
125180
"kernelspec": {
126-
"display_name": "Python [Root]",
181+
"display_name": "Python [conda env:py311_spglm]",
127182
"language": "python",
128-
"name": "Python [Root]"
183+
"name": "conda-env-py311_spglm-py"
129184
},
130185
"language_info": {
131186
"codemirror_mode": {
132187
"name": "ipython",
133-
"version": 2
188+
"version": 3
134189
},
135190
"file_extension": ".py",
136191
"mimetype": "text/x-python",
137192
"name": "python",
138193
"nbconvert_exporter": "python",
139-
"pygments_lexer": "ipython2",
140-
"version": "2.7.12"
194+
"pygments_lexer": "ipython3",
195+
"version": "3.11.6"
141196
}
142197
},
143198
"nbformat": 4,
144-
"nbformat_minor": 1
199+
"nbformat_minor": 4
145200
}

0 commit comments

Comments
 (0)