|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 | 5 | "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 | + }, |
7 | 15 | "outputs": [],
|
8 | 16 | "source": [
|
9 | 17 | "from spglm.glm import GLM\n",
|
10 | 18 | "from spglm.family import Binomial\n",
|
11 |
| - "import libpysal.api as ps\n", |
12 |
| - "import numpy as np" |
| 19 | + "import numpy" |
13 | 20 | ]
|
14 | 21 | },
|
15 | 22 | {
|
16 | 23 | "cell_type": "code",
|
17 | 24 | "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 | + }, |
19 | 34 | "outputs": [],
|
20 | 35 | "source": [
|
21 | 36 | "# 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", |
23 | 38 | "\n",
|
24 | 39 | "#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", |
26 | 41 | " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0,\n",
|
27 | 42 | " 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,\n",
|
28 | 43 | " 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 | 54 | "y = y.reshape((316,1))\n",
|
40 | 55 | "\n",
|
41 | 56 | "#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", |
43 | 58 | " 80, 50, 85, 52, 69, 60, 84, 155, 97, 69, 126, 90, 43,\n",
|
44 | 59 | " 51, 41, 140, 80, 52, 86, 66, 60, 40, 155, 138, 97, 115,\n",
|
45 | 60 | " 148, 206, 60, 53, 96, 88, 160, 31, 43, 154, 60, 131, 60,\n",
|
|
70 | 85 | {
|
71 | 86 | "cell_type": "code",
|
72 | 87 | "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 | + }, |
74 | 97 | "outputs": [],
|
75 | 98 | "source": [
|
76 | 99 | "# Estimate Binomial GLM\n",
|
77 | 100 | "\n",
|
78 | 101 | "# 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", |
82 | 104 | "\n",
|
83 | 105 | "# Then use the fit method to estimate coefficients and compute diagnostics\n",
|
84 | 106 | "results = model.fit()"
|
|
87 | 109 | {
|
88 | 110 | "cell_type": "code",
|
89 | 111 | "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 | + }, |
91 | 121 | "outputs": [
|
92 | 122 | {
|
93 | 123 | "name": "stdout",
|
|
105 | 135 | {
|
106 | 136 | "cell_type": "code",
|
107 | 137 | "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 | + }, |
109 | 147 | "outputs": [
|
110 | 148 | {
|
111 | 149 | "name": "stdout",
|
|
123 | 161 | {
|
124 | 162 | "cell_type": "code",
|
125 | 163 | "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 | + }, |
127 | 173 | "outputs": [
|
128 | 174 | {
|
129 | 175 | "name": "stdout",
|
|
141 | 187 | {
|
142 | 188 | "cell_type": "code",
|
143 | 189 | "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 | + }, |
145 | 199 | "outputs": [
|
146 | 200 | {
|
147 | 201 | "name": "stdout",
|
148 | 202 | "output_type": "stream",
|
149 | 203 | "text": [
|
150 |
| - "155.19347530342466\n" |
| 204 | + "155.1934753034247\n" |
151 | 205 | ]
|
152 | 206 | }
|
153 | 207 | ],
|
|
160 | 214 | "metadata": {
|
161 | 215 | "anaconda-cloud": {},
|
162 | 216 | "kernelspec": {
|
163 |
| - "display_name": "Python [Root]", |
| 217 | + "display_name": "Python [conda env:py311_spglm]", |
164 | 218 | "language": "python",
|
165 |
| - "name": "Python [Root]" |
| 219 | + "name": "conda-env-py311_spglm-py" |
166 | 220 | },
|
167 | 221 | "language_info": {
|
168 | 222 | "codemirror_mode": {
|
169 | 223 | "name": "ipython",
|
170 |
| - "version": 2 |
| 224 | + "version": 3 |
171 | 225 | },
|
172 | 226 | "file_extension": ".py",
|
173 | 227 | "mimetype": "text/x-python",
|
174 | 228 | "name": "python",
|
175 | 229 | "nbconvert_exporter": "python",
|
176 |
| - "pygments_lexer": "ipython2", |
177 |
| - "version": "2.7.12" |
| 230 | + "pygments_lexer": "ipython3", |
| 231 | + "version": "3.11.6" |
178 | 232 | }
|
179 | 233 | },
|
180 | 234 | "nbformat": 4,
|
|
0 commit comments