├── Ch02 ├── data │ ├── AirPassengers.csv │ ├── UNRATE.csv │ ├── donations.csv │ ├── emails.csv │ └── year_joined.csv ├── generateAggregateData.py ├── missing.R ├── smooth.py ├── smoothing.R ├── timeZones.R └── timeZones.py ├── Ch03 ├── acf.R └── periodogram.R ├── Ch04 ├── AgentBasedSimulation.ipynb └── Ising.ipynb ├── Ch07 ├── BSTS.ipynb ├── HMM.ipynb ├── Nile.csv ├── global_temps.csv ├── kalman_filter.r └── kalman_filter_plot.png ├── Ch09 ├── Classification.ipynb ├── Clustering.ipynb └── full_eeg_data_features.csv ├── Ch10 ├── ForecastingElectricity.ipynb └── electricity.txt.gz ├── Ch13 ├── IledeFrance.csv ├── empty.txt └── french_flu.csv ├── Ch14 └── ForecastingStocks.ipynb └── README.md /Ch02/data/AirPassengers.csv: -------------------------------------------------------------------------------- 1 | "1949-01",112 2 | "1949-02",118 3 | "1949-03",132 4 | "1949-04",129 5 | "1949-05",121 6 | "1949-06",135 7 | "1949-07",148 8 | "1949-08",148 9 | "1949-09",136 10 | "1949-10",119 11 | "1949-11",104 12 | "1949-12",118 13 | "1950-01",115 14 | "1950-02",126 15 | "1950-03",141 16 | "1950-04",135 17 | "1950-05",125 18 | "1950-06",149 19 | "1950-07",170 20 | "1950-08",170 21 | "1950-09",158 22 | "1950-10",133 23 | "1950-11",114 24 | "1950-12",140 25 | "1951-01",145 26 | "1951-02",150 27 | "1951-03",178 28 | "1951-04",163 29 | "1951-05",172 30 | "1951-06",178 31 | "1951-07",199 32 | "1951-08",199 33 | "1951-09",184 34 | "1951-10",162 35 | "1951-11",146 36 | "1951-12",166 37 | "1952-01",171 38 | "1952-02",180 39 | "1952-03",193 40 | "1952-04",181 41 | "1952-05",183 42 | "1952-06",218 43 | "1952-07",230 44 | "1952-08",242 45 | "1952-09",209 46 | "1952-10",191 47 | "1952-11",172 48 | "1952-12",194 49 | "1953-01",196 50 | "1953-02",196 51 | "1953-03",236 52 | "1953-04",235 53 | "1953-05",229 54 | "1953-06",243 55 | "1953-07",264 56 | "1953-08",272 57 | "1953-09",237 58 | "1953-10",211 59 | "1953-11",180 60 | "1953-12",201 61 | "1954-01",204 62 | "1954-02",188 63 | "1954-03",235 64 | "1954-04",227 65 | "1954-05",234 66 | "1954-06",264 67 | "1954-07",302 68 | "1954-08",293 69 | "1954-09",259 70 | "1954-10",229 71 | "1954-11",203 72 | "1954-12",229 73 | "1955-01",242 74 | "1955-02",233 75 | "1955-03",267 76 | "1955-04",269 77 | "1955-05",270 78 | "1955-06",315 79 | "1955-07",364 80 | "1955-08",347 81 | "1955-09",312 82 | "1955-10",274 83 | "1955-11",237 84 | "1955-12",278 85 | "1956-01",284 86 | "1956-02",277 87 | "1956-03",317 88 | "1956-04",313 89 | "1956-05",318 90 | "1956-06",374 91 | "1956-07",413 92 | "1956-08",405 93 | "1956-09",355 94 | "1956-10",306 95 | "1956-11",271 96 | "1956-12",306 97 | "1957-01",315 98 | "1957-02",301 99 | "1957-03",356 100 | "1957-04",348 101 | "1957-05",355 102 | "1957-06",422 103 | "1957-07",465 104 | "1957-08",467 105 | "1957-09",404 106 | "1957-10",347 107 | "1957-11",305 108 | "1957-12",336 109 | "1958-01",340 110 | "1958-02",318 111 | "1958-03",362 112 | "1958-04",348 113 | "1958-05",363 114 | "1958-06",435 115 | "1958-07",491 116 | "1958-08",505 117 | "1958-09",404 118 | "1958-10",359 119 | "1958-11",310 120 | "1958-12",337 121 | "1959-01",360 122 | "1959-02",342 123 | "1959-03",406 124 | "1959-04",396 125 | "1959-05",420 126 | "1959-06",472 127 | "1959-07",548 128 | "1959-08",559 129 | "1959-09",463 130 | "1959-10",407 131 | "1959-11",362 132 | "1959-12",405 133 | "1960-01",417 134 | "1960-02",391 135 | "1960-03",419 136 | "1960-04",461 137 | "1960-05",472 138 | "1960-06",535 139 | "1960-07",622 140 | "1960-08",606 141 | "1960-09",508 142 | "1960-10",461 143 | "1960-11",390 144 | "1960-12",432 -------------------------------------------------------------------------------- /Ch02/data/UNRATE.csv: -------------------------------------------------------------------------------- 1 | DATE,UNRATE 2 | 1948-01-01,3.4 3 | 1948-02-01,3.8 4 | 1948-03-01,4.0 5 | 1948-04-01,3.9 6 | 1948-05-01,3.5 7 | 1948-06-01,3.6 8 | 1948-07-01,3.6 9 | 1948-08-01,3.9 10 | 1948-09-01,3.8 11 | 1948-10-01,3.7 12 | 1948-11-01,3.8 13 | 1948-12-01,4.0 14 | 1949-01-01,4.3 15 | 1949-02-01,4.7 16 | 1949-03-01,5.0 17 | 1949-04-01,5.3 18 | 1949-05-01,6.1 19 | 1949-06-01,6.2 20 | 1949-07-01,6.7 21 | 1949-08-01,6.8 22 | 1949-09-01,6.6 23 | 1949-10-01,7.9 24 | 1949-11-01,6.4 25 | 1949-12-01,6.6 26 | 1950-01-01,6.5 27 | 1950-02-01,6.4 28 | 1950-03-01,6.3 29 | 1950-04-01,5.8 30 | 1950-05-01,5.5 31 | 1950-06-01,5.4 32 | 1950-07-01,5.0 33 | 1950-08-01,4.5 34 | 1950-09-01,4.4 35 | 1950-10-01,4.2 36 | 1950-11-01,4.2 37 | 1950-12-01,4.3 38 | 1951-01-01,3.7 39 | 1951-02-01,3.4 40 | 1951-03-01,3.4 41 | 1951-04-01,3.1 42 | 1951-05-01,3.0 43 | 1951-06-01,3.2 44 | 1951-07-01,3.1 45 | 1951-08-01,3.1 46 | 1951-09-01,3.3 47 | 1951-10-01,3.5 48 | 1951-11-01,3.5 49 | 1951-12-01,3.1 50 | 1952-01-01,3.2 51 | 1952-02-01,3.1 52 | 1952-03-01,2.9 53 | 1952-04-01,2.9 54 | 1952-05-01,3.0 55 | 1952-06-01,3.0 56 | 1952-07-01,3.2 57 | 1952-08-01,3.4 58 | 1952-09-01,3.1 59 | 1952-10-01,3.0 60 | 1952-11-01,2.8 61 | 1952-12-01,2.7 62 | 1953-01-01,2.9 63 | 1953-02-01,2.6 64 | 1953-03-01,2.6 65 | 1953-04-01,2.7 66 | 1953-05-01,2.5 67 | 1953-06-01,2.5 68 | 1953-07-01,2.6 69 | 1953-08-01,2.7 70 | 1953-09-01,2.9 71 | 1953-10-01,3.1 72 | 1953-11-01,3.5 73 | 1953-12-01,4.5 74 | 1954-01-01,4.9 75 | 1954-02-01,5.2 76 | 1954-03-01,5.7 77 | 1954-04-01,5.9 78 | 1954-05-01,5.9 79 | 1954-06-01,5.6 80 | 1954-07-01,5.8 81 | 1954-08-01,6.0 82 | 1954-09-01,6.1 83 | 1954-10-01,5.7 84 | 1954-11-01,5.3 85 | 1954-12-01,5.0 86 | 1955-01-01,4.9 87 | 1955-02-01,4.7 88 | 1955-03-01,4.6 89 | 1955-04-01,4.7 90 | 1955-05-01,4.3 91 | 1955-06-01,4.2 92 | 1955-07-01,4.0 93 | 1955-08-01,4.2 94 | 1955-09-01,4.1 95 | 1955-10-01,4.3 96 | 1955-11-01,4.2 97 | 1955-12-01,4.2 98 | 1956-01-01,4.0 99 | 1956-02-01,3.9 100 | 1956-03-01,4.2 101 | 1956-04-01,4.0 102 | 1956-05-01,4.3 103 | 1956-06-01,4.3 104 | 1956-07-01,4.4 105 | 1956-08-01,4.1 106 | 1956-09-01,3.9 107 | 1956-10-01,3.9 108 | 1956-11-01,4.3 109 | 1956-12-01,4.2 110 | 1957-01-01,4.2 111 | 1957-02-01,3.9 112 | 1957-03-01,3.7 113 | 1957-04-01,3.9 114 | 1957-05-01,4.1 115 | 1957-06-01,4.3 116 | 1957-07-01,4.2 117 | 1957-08-01,4.1 118 | 1957-09-01,4.4 119 | 1957-10-01,4.5 120 | 1957-11-01,5.1 121 | 1957-12-01,5.2 122 | 1958-01-01,5.8 123 | 1958-02-01,6.4 124 | 1958-03-01,6.7 125 | 1958-04-01,7.4 126 | 1958-05-01,7.4 127 | 1958-06-01,7.3 128 | 1958-07-01,7.5 129 | 1958-08-01,7.4 130 | 1958-09-01,7.1 131 | 1958-10-01,6.7 132 | 1958-11-01,6.2 133 | 1958-12-01,6.2 134 | 1959-01-01,6.0 135 | 1959-02-01,5.9 136 | 1959-03-01,5.6 137 | 1959-04-01,5.2 138 | 1959-05-01,5.1 139 | 1959-06-01,5.0 140 | 1959-07-01,5.1 141 | 1959-08-01,5.2 142 | 1959-09-01,5.5 143 | 1959-10-01,5.7 144 | 1959-11-01,5.8 145 | 1959-12-01,5.3 146 | 1960-01-01,5.2 147 | 1960-02-01,4.8 148 | 1960-03-01,5.4 149 | 1960-04-01,5.2 150 | 1960-05-01,5.1 151 | 1960-06-01,5.4 152 | 1960-07-01,5.5 153 | 1960-08-01,5.6 154 | 1960-09-01,5.5 155 | 1960-10-01,6.1 156 | 1960-11-01,6.1 157 | 1960-12-01,6.6 158 | 1961-01-01,6.6 159 | 1961-02-01,6.9 160 | 1961-03-01,6.9 161 | 1961-04-01,7.0 162 | 1961-05-01,7.1 163 | 1961-06-01,6.9 164 | 1961-07-01,7.0 165 | 1961-08-01,6.6 166 | 1961-09-01,6.7 167 | 1961-10-01,6.5 168 | 1961-11-01,6.1 169 | 1961-12-01,6.0 170 | 1962-01-01,5.8 171 | 1962-02-01,5.5 172 | 1962-03-01,5.6 173 | 1962-04-01,5.6 174 | 1962-05-01,5.5 175 | 1962-06-01,5.5 176 | 1962-07-01,5.4 177 | 1962-08-01,5.7 178 | 1962-09-01,5.6 179 | 1962-10-01,5.4 180 | 1962-11-01,5.7 181 | 1962-12-01,5.5 182 | 1963-01-01,5.7 183 | 1963-02-01,5.9 184 | 1963-03-01,5.7 185 | 1963-04-01,5.7 186 | 1963-05-01,5.9 187 | 1963-06-01,5.6 188 | 1963-07-01,5.6 189 | 1963-08-01,5.4 190 | 1963-09-01,5.5 191 | 1963-10-01,5.5 192 | 1963-11-01,5.7 193 | 1963-12-01,5.5 194 | 1964-01-01,5.6 195 | 1964-02-01,5.4 196 | 1964-03-01,5.4 197 | 1964-04-01,5.3 198 | 1964-05-01,5.1 199 | 1964-06-01,5.2 200 | 1964-07-01,4.9 201 | 1964-08-01,5.0 202 | 1964-09-01,5.1 203 | 1964-10-01,5.1 204 | 1964-11-01,4.8 205 | 1964-12-01,5.0 206 | 1965-01-01,4.9 207 | 1965-02-01,5.1 208 | 1965-03-01,4.7 209 | 1965-04-01,4.8 210 | 1965-05-01,4.6 211 | 1965-06-01,4.6 212 | 1965-07-01,4.4 213 | 1965-08-01,4.4 214 | 1965-09-01,4.3 215 | 1965-10-01,4.2 216 | 1965-11-01,4.1 217 | 1965-12-01,4.0 218 | 1966-01-01,4.0 219 | 1966-02-01,3.8 220 | 1966-03-01,3.8 221 | 1966-04-01,3.8 222 | 1966-05-01,3.9 223 | 1966-06-01,3.8 224 | 1966-07-01,3.8 225 | 1966-08-01,3.8 226 | 1966-09-01,3.7 227 | 1966-10-01,3.7 228 | 1966-11-01,3.6 229 | 1966-12-01,3.8 230 | 1967-01-01,3.9 231 | 1967-02-01,3.8 232 | 1967-03-01,3.8 233 | 1967-04-01,3.8 234 | 1967-05-01,3.8 235 | 1967-06-01,3.9 236 | 1967-07-01,3.8 237 | 1967-08-01,3.8 238 | 1967-09-01,3.8 239 | 1967-10-01,4.0 240 | 1967-11-01,3.9 241 | 1967-12-01,3.8 242 | 1968-01-01,3.7 243 | 1968-02-01,3.8 244 | 1968-03-01,3.7 245 | 1968-04-01,3.5 246 | 1968-05-01,3.5 247 | 1968-06-01,3.7 248 | 1968-07-01,3.7 249 | 1968-08-01,3.5 250 | 1968-09-01,3.4 251 | 1968-10-01,3.4 252 | 1968-11-01,3.4 253 | 1968-12-01,3.4 254 | 1969-01-01,3.4 255 | 1969-02-01,3.4 256 | 1969-03-01,3.4 257 | 1969-04-01,3.4 258 | 1969-05-01,3.4 259 | 1969-06-01,3.5 260 | 1969-07-01,3.5 261 | 1969-08-01,3.5 262 | 1969-09-01,3.7 263 | 1969-10-01,3.7 264 | 1969-11-01,3.5 265 | 1969-12-01,3.5 266 | 1970-01-01,3.9 267 | 1970-02-01,4.2 268 | 1970-03-01,4.4 269 | 1970-04-01,4.6 270 | 1970-05-01,4.8 271 | 1970-06-01,4.9 272 | 1970-07-01,5.0 273 | 1970-08-01,5.1 274 | 1970-09-01,5.4 275 | 1970-10-01,5.5 276 | 1970-11-01,5.9 277 | 1970-12-01,6.1 278 | 1971-01-01,5.9 279 | 1971-02-01,5.9 280 | 1971-03-01,6.0 281 | 1971-04-01,5.9 282 | 1971-05-01,5.9 283 | 1971-06-01,5.9 284 | 1971-07-01,6.0 285 | 1971-08-01,6.1 286 | 1971-09-01,6.0 287 | 1971-10-01,5.8 288 | 1971-11-01,6.0 289 | 1971-12-01,6.0 290 | 1972-01-01,5.8 291 | 1972-02-01,5.7 292 | 1972-03-01,5.8 293 | 1972-04-01,5.7 294 | 1972-05-01,5.7 295 | 1972-06-01,5.7 296 | 1972-07-01,5.6 297 | 1972-08-01,5.6 298 | 1972-09-01,5.5 299 | 1972-10-01,5.6 300 | 1972-11-01,5.3 301 | 1972-12-01,5.2 302 | 1973-01-01,4.9 303 | 1973-02-01,5.0 304 | 1973-03-01,4.9 305 | 1973-04-01,5.0 306 | 1973-05-01,4.9 307 | 1973-06-01,4.9 308 | 1973-07-01,4.8 309 | 1973-08-01,4.8 310 | 1973-09-01,4.8 311 | 1973-10-01,4.6 312 | 1973-11-01,4.8 313 | 1973-12-01,4.9 314 | 1974-01-01,5.1 315 | 1974-02-01,5.2 316 | 1974-03-01,5.1 317 | 1974-04-01,5.1 318 | 1974-05-01,5.1 319 | 1974-06-01,5.4 320 | 1974-07-01,5.5 321 | 1974-08-01,5.5 322 | 1974-09-01,5.9 323 | 1974-10-01,6.0 324 | 1974-11-01,6.6 325 | 1974-12-01,7.2 326 | 1975-01-01,8.1 327 | 1975-02-01,8.1 328 | 1975-03-01,8.6 329 | 1975-04-01,8.8 330 | 1975-05-01,9.0 331 | 1975-06-01,8.8 332 | 1975-07-01,8.6 333 | 1975-08-01,8.4 334 | 1975-09-01,8.4 335 | 1975-10-01,8.4 336 | 1975-11-01,8.3 337 | 1975-12-01,8.2 338 | 1976-01-01,7.9 339 | 1976-02-01,7.7 340 | 1976-03-01,7.6 341 | 1976-04-01,7.7 342 | 1976-05-01,7.4 343 | 1976-06-01,7.6 344 | 1976-07-01,7.8 345 | 1976-08-01,7.8 346 | 1976-09-01,7.6 347 | 1976-10-01,7.7 348 | 1976-11-01,7.8 349 | 1976-12-01,7.8 350 | 1977-01-01,7.5 351 | 1977-02-01,7.6 352 | 1977-03-01,7.4 353 | 1977-04-01,7.2 354 | 1977-05-01,7.0 355 | 1977-06-01,7.2 356 | 1977-07-01,6.9 357 | 1977-08-01,7.0 358 | 1977-09-01,6.8 359 | 1977-10-01,6.8 360 | 1977-11-01,6.8 361 | 1977-12-01,6.4 362 | 1978-01-01,6.4 363 | 1978-02-01,6.3 364 | 1978-03-01,6.3 365 | 1978-04-01,6.1 366 | 1978-05-01,6.0 367 | 1978-06-01,5.9 368 | 1978-07-01,6.2 369 | 1978-08-01,5.9 370 | 1978-09-01,6.0 371 | 1978-10-01,5.8 372 | 1978-11-01,5.9 373 | 1978-12-01,6.0 374 | 1979-01-01,5.9 375 | 1979-02-01,5.9 376 | 1979-03-01,5.8 377 | 1979-04-01,5.8 378 | 1979-05-01,5.6 379 | 1979-06-01,5.7 380 | 1979-07-01,5.7 381 | 1979-08-01,6.0 382 | 1979-09-01,5.9 383 | 1979-10-01,6.0 384 | 1979-11-01,5.9 385 | 1979-12-01,6.0 386 | 1980-01-01,6.3 387 | 1980-02-01,6.3 388 | 1980-03-01,6.3 389 | 1980-04-01,6.9 390 | 1980-05-01,7.5 391 | 1980-06-01,7.6 392 | 1980-07-01,7.8 393 | 1980-08-01,7.7 394 | 1980-09-01,7.5 395 | 1980-10-01,7.5 396 | 1980-11-01,7.5 397 | 1980-12-01,7.2 398 | 1981-01-01,7.5 399 | 1981-02-01,7.4 400 | 1981-03-01,7.4 401 | 1981-04-01,7.2 402 | 1981-05-01,7.5 403 | 1981-06-01,7.5 404 | 1981-07-01,7.2 405 | 1981-08-01,7.4 406 | 1981-09-01,7.6 407 | 1981-10-01,7.9 408 | 1981-11-01,8.3 409 | 1981-12-01,8.5 410 | 1982-01-01,8.6 411 | 1982-02-01,8.9 412 | 1982-03-01,9.0 413 | 1982-04-01,9.3 414 | 1982-05-01,9.4 415 | 1982-06-01,9.6 416 | 1982-07-01,9.8 417 | 1982-08-01,9.8 418 | 1982-09-01,10.1 419 | 1982-10-01,10.4 420 | 1982-11-01,10.8 421 | 1982-12-01,10.8 422 | 1983-01-01,10.4 423 | 1983-02-01,10.4 424 | 1983-03-01,10.3 425 | 1983-04-01,10.2 426 | 1983-05-01,10.1 427 | 1983-06-01,10.1 428 | 1983-07-01,9.4 429 | 1983-08-01,9.5 430 | 1983-09-01,9.2 431 | 1983-10-01,8.8 432 | 1983-11-01,8.5 433 | 1983-12-01,8.3 434 | 1984-01-01,8.0 435 | 1984-02-01,7.8 436 | 1984-03-01,7.8 437 | 1984-04-01,7.7 438 | 1984-05-01,7.4 439 | 1984-06-01,7.2 440 | 1984-07-01,7.5 441 | 1984-08-01,7.5 442 | 1984-09-01,7.3 443 | 1984-10-01,7.4 444 | 1984-11-01,7.2 445 | 1984-12-01,7.3 446 | 1985-01-01,7.3 447 | 1985-02-01,7.2 448 | 1985-03-01,7.2 449 | 1985-04-01,7.3 450 | 1985-05-01,7.2 451 | 1985-06-01,7.4 452 | 1985-07-01,7.4 453 | 1985-08-01,7.1 454 | 1985-09-01,7.1 455 | 1985-10-01,7.1 456 | 1985-11-01,7.0 457 | 1985-12-01,7.0 458 | 1986-01-01,6.7 459 | 1986-02-01,7.2 460 | 1986-03-01,7.2 461 | 1986-04-01,7.1 462 | 1986-05-01,7.2 463 | 1986-06-01,7.2 464 | 1986-07-01,7.0 465 | 1986-08-01,6.9 466 | 1986-09-01,7.0 467 | 1986-10-01,7.0 468 | 1986-11-01,6.9 469 | 1986-12-01,6.6 470 | 1987-01-01,6.6 471 | 1987-02-01,6.6 472 | 1987-03-01,6.6 473 | 1987-04-01,6.3 474 | 1987-05-01,6.3 475 | 1987-06-01,6.2 476 | 1987-07-01,6.1 477 | 1987-08-01,6.0 478 | 1987-09-01,5.9 479 | 1987-10-01,6.0 480 | 1987-11-01,5.8 481 | 1987-12-01,5.7 482 | 1988-01-01,5.7 483 | 1988-02-01,5.7 484 | 1988-03-01,5.7 485 | 1988-04-01,5.4 486 | 1988-05-01,5.6 487 | 1988-06-01,5.4 488 | 1988-07-01,5.4 489 | 1988-08-01,5.6 490 | 1988-09-01,5.4 491 | 1988-10-01,5.4 492 | 1988-11-01,5.3 493 | 1988-12-01,5.3 494 | 1989-01-01,5.4 495 | 1989-02-01,5.2 496 | 1989-03-01,5.0 497 | 1989-04-01,5.2 498 | 1989-05-01,5.2 499 | 1989-06-01,5.3 500 | 1989-07-01,5.2 501 | 1989-08-01,5.2 502 | 1989-09-01,5.3 503 | 1989-10-01,5.3 504 | 1989-11-01,5.4 505 | 1989-12-01,5.4 506 | 1990-01-01,5.4 507 | 1990-02-01,5.3 508 | 1990-03-01,5.2 509 | 1990-04-01,5.4 510 | 1990-05-01,5.4 511 | 1990-06-01,5.2 512 | 1990-07-01,5.5 513 | 1990-08-01,5.7 514 | 1990-09-01,5.9 515 | 1990-10-01,5.9 516 | 1990-11-01,6.2 517 | 1990-12-01,6.3 518 | 1991-01-01,6.4 519 | 1991-02-01,6.6 520 | 1991-03-01,6.8 521 | 1991-04-01,6.7 522 | 1991-05-01,6.9 523 | 1991-06-01,6.9 524 | 1991-07-01,6.8 525 | 1991-08-01,6.9 526 | 1991-09-01,6.9 527 | 1991-10-01,7.0 528 | 1991-11-01,7.0 529 | 1991-12-01,7.3 530 | 1992-01-01,7.3 531 | 1992-02-01,7.4 532 | 1992-03-01,7.4 533 | 1992-04-01,7.4 534 | 1992-05-01,7.6 535 | 1992-06-01,7.8 536 | 1992-07-01,7.7 537 | 1992-08-01,7.6 538 | 1992-09-01,7.6 539 | 1992-10-01,7.3 540 | 1992-11-01,7.4 541 | 1992-12-01,7.4 542 | 1993-01-01,7.3 543 | 1993-02-01,7.1 544 | 1993-03-01,7.0 545 | 1993-04-01,7.1 546 | 1993-05-01,7.1 547 | 1993-06-01,7.0 548 | 1993-07-01,6.9 549 | 1993-08-01,6.8 550 | 1993-09-01,6.7 551 | 1993-10-01,6.8 552 | 1993-11-01,6.6 553 | 1993-12-01,6.5 554 | 1994-01-01,6.6 555 | 1994-02-01,6.6 556 | 1994-03-01,6.5 557 | 1994-04-01,6.4 558 | 1994-05-01,6.1 559 | 1994-06-01,6.1 560 | 1994-07-01,6.1 561 | 1994-08-01,6.0 562 | 1994-09-01,5.9 563 | 1994-10-01,5.8 564 | 1994-11-01,5.6 565 | 1994-12-01,5.5 566 | 1995-01-01,5.6 567 | 1995-02-01,5.4 568 | 1995-03-01,5.4 569 | 1995-04-01,5.8 570 | 1995-05-01,5.6 571 | 1995-06-01,5.6 572 | 1995-07-01,5.7 573 | 1995-08-01,5.7 574 | 1995-09-01,5.6 575 | 1995-10-01,5.5 576 | 1995-11-01,5.6 577 | 1995-12-01,5.6 578 | 1996-01-01,5.6 579 | 1996-02-01,5.5 580 | 1996-03-01,5.5 581 | 1996-04-01,5.6 582 | 1996-05-01,5.6 583 | 1996-06-01,5.3 584 | 1996-07-01,5.5 585 | 1996-08-01,5.1 586 | 1996-09-01,5.2 587 | 1996-10-01,5.2 588 | 1996-11-01,5.4 589 | 1996-12-01,5.4 590 | 1997-01-01,5.3 591 | 1997-02-01,5.2 592 | 1997-03-01,5.2 593 | 1997-04-01,5.1 594 | 1997-05-01,4.9 595 | 1997-06-01,5.0 596 | 1997-07-01,4.9 597 | 1997-08-01,4.8 598 | 1997-09-01,4.9 599 | 1997-10-01,4.7 600 | 1997-11-01,4.6 601 | 1997-12-01,4.7 602 | 1998-01-01,4.6 603 | 1998-02-01,4.6 604 | 1998-03-01,4.7 605 | 1998-04-01,4.3 606 | 1998-05-01,4.4 607 | 1998-06-01,4.5 608 | 1998-07-01,4.5 609 | 1998-08-01,4.5 610 | 1998-09-01,4.6 611 | 1998-10-01,4.5 612 | 1998-11-01,4.4 613 | 1998-12-01,4.4 614 | 1999-01-01,4.3 615 | 1999-02-01,4.4 616 | 1999-03-01,4.2 617 | 1999-04-01,4.3 618 | 1999-05-01,4.2 619 | 1999-06-01,4.3 620 | 1999-07-01,4.3 621 | 1999-08-01,4.2 622 | 1999-09-01,4.2 623 | 1999-10-01,4.1 624 | 1999-11-01,4.1 625 | 1999-12-01,4.0 626 | 2000-01-01,4.0 627 | 2000-02-01,4.1 628 | 2000-03-01,4.0 629 | 2000-04-01,3.8 630 | 2000-05-01,4.0 631 | 2000-06-01,4.0 632 | 2000-07-01,4.0 633 | 2000-08-01,4.1 634 | 2000-09-01,3.9 635 | 2000-10-01,3.9 636 | 2000-11-01,3.9 637 | 2000-12-01,3.9 638 | 2001-01-01,4.2 639 | 2001-02-01,4.2 640 | 2001-03-01,4.3 641 | 2001-04-01,4.4 642 | 2001-05-01,4.3 643 | 2001-06-01,4.5 644 | 2001-07-01,4.6 645 | 2001-08-01,4.9 646 | 2001-09-01,5.0 647 | 2001-10-01,5.3 648 | 2001-11-01,5.5 649 | 2001-12-01,5.7 650 | 2002-01-01,5.7 651 | 2002-02-01,5.7 652 | 2002-03-01,5.7 653 | 2002-04-01,5.9 654 | 2002-05-01,5.8 655 | 2002-06-01,5.8 656 | 2002-07-01,5.8 657 | 2002-08-01,5.7 658 | 2002-09-01,5.7 659 | 2002-10-01,5.7 660 | 2002-11-01,5.9 661 | 2002-12-01,6.0 662 | 2003-01-01,5.8 663 | 2003-02-01,5.9 664 | 2003-03-01,5.9 665 | 2003-04-01,6.0 666 | 2003-05-01,6.1 667 | 2003-06-01,6.3 668 | 2003-07-01,6.2 669 | 2003-08-01,6.1 670 | 2003-09-01,6.1 671 | 2003-10-01,6.0 672 | 2003-11-01,5.8 673 | 2003-12-01,5.7 674 | 2004-01-01,5.7 675 | 2004-02-01,5.6 676 | 2004-03-01,5.8 677 | 2004-04-01,5.6 678 | 2004-05-01,5.6 679 | 2004-06-01,5.6 680 | 2004-07-01,5.5 681 | 2004-08-01,5.4 682 | 2004-09-01,5.4 683 | 2004-10-01,5.5 684 | 2004-11-01,5.4 685 | 2004-12-01,5.4 686 | 2005-01-01,5.3 687 | 2005-02-01,5.4 688 | 2005-03-01,5.2 689 | 2005-04-01,5.2 690 | 2005-05-01,5.1 691 | 2005-06-01,5.0 692 | 2005-07-01,5.0 693 | 2005-08-01,4.9 694 | 2005-09-01,5.0 695 | 2005-10-01,5.0 696 | 2005-11-01,5.0 697 | 2005-12-01,4.9 698 | 2006-01-01,4.7 699 | 2006-02-01,4.8 700 | 2006-03-01,4.7 701 | 2006-04-01,4.7 702 | 2006-05-01,4.6 703 | 2006-06-01,4.6 704 | 2006-07-01,4.7 705 | 2006-08-01,4.7 706 | 2006-09-01,4.5 707 | 2006-10-01,4.4 708 | 2006-11-01,4.5 709 | 2006-12-01,4.4 710 | 2007-01-01,4.6 711 | 2007-02-01,4.5 712 | 2007-03-01,4.4 713 | 2007-04-01,4.5 714 | 2007-05-01,4.4 715 | 2007-06-01,4.6 716 | 2007-07-01,4.7 717 | 2007-08-01,4.6 718 | 2007-09-01,4.7 719 | 2007-10-01,4.7 720 | 2007-11-01,4.7 721 | 2007-12-01,5.0 722 | 2008-01-01,5.0 723 | 2008-02-01,4.9 724 | 2008-03-01,5.1 725 | 2008-04-01,5.0 726 | 2008-05-01,5.4 727 | 2008-06-01,5.6 728 | 2008-07-01,5.8 729 | 2008-08-01,6.1 730 | 2008-09-01,6.1 731 | 2008-10-01,6.5 732 | 2008-11-01,6.8 733 | 2008-12-01,7.3 734 | 2009-01-01,7.8 735 | 2009-02-01,8.3 736 | 2009-03-01,8.7 737 | 2009-04-01,9.0 738 | 2009-05-01,9.4 739 | 2009-06-01,9.5 740 | 2009-07-01,9.5 741 | 2009-08-01,9.6 742 | 2009-09-01,9.8 743 | 2009-10-01,10.0 744 | 2009-11-01,9.9 745 | 2009-12-01,9.9 746 | 2010-01-01,9.8 747 | 2010-02-01,9.8 748 | 2010-03-01,9.9 749 | 2010-04-01,9.9 750 | 2010-05-01,9.6 751 | 2010-06-01,9.4 752 | 2010-07-01,9.4 753 | 2010-08-01,9.5 754 | 2010-09-01,9.5 755 | 2010-10-01,9.4 756 | 2010-11-01,9.8 757 | 2010-12-01,9.3 758 | 2011-01-01,9.1 759 | 2011-02-01,9.0 760 | 2011-03-01,9.0 761 | 2011-04-01,9.1 762 | 2011-05-01,9.0 763 | 2011-06-01,9.1 764 | 2011-07-01,9.0 765 | 2011-08-01,9.0 766 | 2011-09-01,9.0 767 | 2011-10-01,8.8 768 | 2011-11-01,8.6 769 | 2011-12-01,8.5 770 | 2012-01-01,8.3 771 | 2012-02-01,8.3 772 | 2012-03-01,8.2 773 | 2012-04-01,8.2 774 | 2012-05-01,8.2 775 | 2012-06-01,8.2 776 | 2012-07-01,8.2 777 | 2012-08-01,8.1 778 | 2012-09-01,7.8 779 | 2012-10-01,7.8 780 | 2012-11-01,7.7 781 | 2012-12-01,7.9 782 | 2013-01-01,8.0 783 | 2013-02-01,7.7 784 | 2013-03-01,7.5 785 | 2013-04-01,7.6 786 | 2013-05-01,7.5 787 | 2013-06-01,7.5 788 | 2013-07-01,7.3 789 | 2013-08-01,7.2 790 | 2013-09-01,7.2 791 | 2013-10-01,7.2 792 | 2013-11-01,6.9 793 | 2013-12-01,6.7 794 | 2014-01-01,6.6 795 | 2014-02-01,6.7 796 | 2014-03-01,6.7 797 | 2014-04-01,6.3 798 | 2014-05-01,6.3 799 | 2014-06-01,6.1 800 | 2014-07-01,6.2 801 | 2014-08-01,6.2 802 | 2014-09-01,5.9 803 | 2014-10-01,5.7 804 | 2014-11-01,5.8 805 | 2014-12-01,5.6 806 | 2015-01-01,5.7 807 | 2015-02-01,5.5 808 | 2015-03-01,5.5 809 | 2015-04-01,5.4 810 | 2015-05-01,5.5 811 | 2015-06-01,5.3 812 | 2015-07-01,5.2 813 | 2015-08-01,5.1 814 | 2015-09-01,5.0 815 | 2015-10-01,5.0 816 | 2015-11-01,5.0 817 | 2015-12-01,5.0 818 | 2016-01-01,4.9 819 | 2016-02-01,4.9 820 | 2016-03-01,5.0 821 | 2016-04-01,5.0 822 | 2016-05-01,4.7 823 | 2016-06-01,4.9 824 | 2016-07-01,4.9 825 | 2016-08-01,4.9 826 | 2016-09-01,5.0 827 | 2016-10-01,4.9 828 | 2016-11-01,4.6 829 | 2016-12-01,4.7 830 | 2017-01-01,4.8 831 | 2017-02-01,4.7 832 | 2017-03-01,4.5 833 | 2017-04-01,4.4 834 | 2017-05-01,4.3 835 | 2017-06-01,4.3 836 | 2017-07-01,4.3 837 | 2017-08-01,4.4 838 | 2017-09-01,4.2 839 | 2017-10-01,4.1 840 | 2017-11-01,4.1 841 | 2017-12-01,4.1 842 | 2018-01-01,4.1 843 | 2018-02-01,4.1 844 | 2018-03-01,4.1 845 | 2018-04-01,3.9 846 | -------------------------------------------------------------------------------- /Ch02/data/year_joined.csv: -------------------------------------------------------------------------------- 1 | user,userStats,yearJoined 2 | 0,silver,2014 3 | 1,silver,2015 4 | 2,silver,2016 5 | 3,bronze,2018 6 | 4,silver,2018 7 | 5,bronze,2017 8 | 6,inactive,2016 9 | 7,silver,2018 10 | 8,inactive,2017 11 | 9,silver,2016 12 | 10,silver,2014 13 | 11,silver,2015 14 | 12,gold,2018 15 | 13,silver,2018 16 | 14,bronze,2016 17 | 15,silver,2017 18 | 16,bronze,2017 19 | 17,silver,2018 20 | 18,bronze,2015 21 | 19,bronze,2016 22 | 20,inactive,2016 23 | 21,gold,2018 24 | 22,bronze,2018 25 | 23,gold,2017 26 | 24,gold,2016 27 | 25,inactive,2014 28 | 26,silver,2017 29 | 27,silver,2018 30 | 28,bronze,2016 31 | 29,bronze,2016 32 | 30,silver,2018 33 | 31,gold,2014 34 | 32,inactive,2018 35 | 33,silver,2015 36 | 34,bronze,2015 37 | 35,gold,2015 38 | 36,bronze,2018 39 | 37,silver,2018 40 | 38,gold,2014 41 | 39,gold,2017 42 | 40,silver,2017 43 | 41,bronze,2016 44 | 42,bronze,2015 45 | 43,silver,2018 46 | 44,inactive,2018 47 | 45,bronze,2016 48 | 46,bronze,2017 49 | 47,bronze,2018 50 | 48,bronze,2018 51 | 49,gold,2018 52 | 50,bronze,2017 53 | 51,bronze,2017 54 | 52,bronze,2016 55 | 53,silver,2018 56 | 54,silver,2014 57 | 55,bronze,2018 58 | 56,silver,2017 59 | 57,bronze,2016 60 | 58,bronze,2017 61 | 59,bronze,2017 62 | 60,inactive,2018 63 | 61,bronze,2018 64 | 62,bronze,2018 65 | 63,inactive,2017 66 | 64,bronze,2016 67 | 65,bronze,2017 68 | 66,gold,2017 69 | 67,bronze,2018 70 | 68,gold,2015 71 | 69,gold,2017 72 | 70,bronze,2017 73 | 71,bronze,2016 74 | 72,silver,2018 75 | 73,gold,2017 76 | 74,inactive,2016 77 | 75,bronze,2014 78 | 76,bronze,2017 79 | 77,bronze,2018 80 | 78,silver,2017 81 | 79,silver,2018 82 | 80,bronze,2016 83 | 81,inactive,2014 84 | 82,inactive,2018 85 | 83,bronze,2014 86 | 84,bronze,2017 87 | 85,bronze,2015 88 | 86,gold,2016 89 | 87,silver,2018 90 | 88,bronze,2017 91 | 89,inactive,2016 92 | 90,bronze,2015 93 | 91,bronze,2018 94 | 92,bronze,2018 95 | 93,silver,2015 96 | 94,bronze,2018 97 | 95,bronze,2014 98 | 96,silver,2015 99 | 97,gold,2017 100 | 98,silver,2014 101 | 99,silver,2018 102 | 100,bronze,2017 103 | 101,bronze,2016 104 | 102,silver,2016 105 | 103,bronze,2016 106 | 104,gold,2016 107 | 105,gold,2018 108 | 106,silver,2018 109 | 107,inactive,2016 110 | 108,bronze,2016 111 | 109,silver,2017 112 | 110,bronze,2017 113 | 111,silver,2015 114 | 112,silver,2016 115 | 113,bronze,2016 116 | 114,silver,2017 117 | 115,inactive,2018 118 | 116,silver,2014 119 | 117,bronze,2017 120 | 118,silver,2018 121 | 119,silver,2017 122 | 120,silver,2017 123 | 121,bronze,2017 124 | 122,bronze,2016 125 | 123,silver,2018 126 | 124,bronze,2017 127 | 125,bronze,2017 128 | 126,bronze,2017 129 | 127,silver,2016 130 | 128,silver,2016 131 | 129,silver,2015 132 | 130,bronze,2016 133 | 131,bronze,2017 134 | 132,bronze,2017 135 | 133,gold,2015 136 | 134,inactive,2014 137 | 135,silver,2014 138 | 136,bronze,2018 139 | 137,bronze,2015 140 | 138,gold,2016 141 | 139,bronze,2017 142 | 140,silver,2018 143 | 141,silver,2018 144 | 142,silver,2018 145 | 143,gold,2018 146 | 144,silver,2015 147 | 145,gold,2017 148 | 146,inactive,2015 149 | 147,inactive,2018 150 | 148,silver,2015 151 | 149,silver,2016 152 | 150,inactive,2018 153 | 151,silver,2015 154 | 152,bronze,2016 155 | 153,bronze,2014 156 | 154,bronze,2018 157 | 155,bronze,2014 158 | 156,bronze,2018 159 | 157,bronze,2018 160 | 158,bronze,2017 161 | 159,bronze,2015 162 | 160,bronze,2017 163 | 161,bronze,2016 164 | 162,bronze,2017 165 | 163,gold,2017 166 | 164,silver,2018 167 | 165,inactive,2017 168 | 166,inactive,2017 169 | 167,silver,2018 170 | 168,silver,2017 171 | 169,bronze,2017 172 | 170,bronze,2017 173 | 171,silver,2018 174 | 172,bronze,2018 175 | 173,bronze,2018 176 | 174,bronze,2014 177 | 175,silver,2015 178 | 176,bronze,2015 179 | 177,bronze,2014 180 | 178,gold,2018 181 | 179,bronze,2017 182 | 180,bronze,2015 183 | 181,bronze,2017 184 | 182,silver,2018 185 | 183,gold,2018 186 | 184,silver,2018 187 | 185,bronze,2017 188 | 186,gold,2017 189 | 187,silver,2017 190 | 188,bronze,2016 191 | 189,silver,2018 192 | 190,bronze,2018 193 | 191,gold,2018 194 | 192,inactive,2014 195 | 193,silver,2018 196 | 194,silver,2018 197 | 195,silver,2018 198 | 196,gold,2017 199 | 197,silver,2015 200 | 198,bronze,2018 201 | 199,inactive,2017 202 | 200,silver,2017 203 | 201,bronze,2016 204 | 202,bronze,2016 205 | 203,silver,2018 206 | 204,bronze,2016 207 | 205,bronze,2016 208 | 206,inactive,2017 209 | 207,bronze,2014 210 | 208,silver,2017 211 | 209,silver,2018 212 | 210,bronze,2018 213 | 211,bronze,2015 214 | 212,bronze,2017 215 | 213,gold,2015 216 | 214,silver,2014 217 | 215,bronze,2018 218 | 216,bronze,2018 219 | 217,bronze,2016 220 | 218,bronze,2017 221 | 219,bronze,2015 222 | 220,inactive,2014 223 | 221,bronze,2015 224 | 222,bronze,2017 225 | 223,bronze,2018 226 | 224,silver,2015 227 | 225,bronze,2018 228 | 226,gold,2017 229 | 227,silver,2015 230 | 228,bronze,2018 231 | 229,gold,2018 232 | 230,silver,2014 233 | 231,bronze,2016 234 | 232,silver,2016 235 | 233,bronze,2017 236 | 234,silver,2017 237 | 235,silver,2018 238 | 236,bronze,2014 239 | 237,bronze,2016 240 | 238,gold,2016 241 | 239,gold,2017 242 | 240,bronze,2016 243 | 241,bronze,2017 244 | 242,silver,2018 245 | 243,gold,2017 246 | 244,bronze,2018 247 | 245,bronze,2017 248 | 246,silver,2016 249 | 247,bronze,2017 250 | 248,silver,2018 251 | 249,bronze,2017 252 | 250,inactive,2017 253 | 251,bronze,2018 254 | 252,bronze,2016 255 | 253,bronze,2018 256 | 254,bronze,2018 257 | 255,bronze,2018 258 | 256,silver,2017 259 | 257,inactive,2018 260 | 258,bronze,2017 261 | 259,bronze,2017 262 | 260,bronze,2017 263 | 261,bronze,2017 264 | 262,silver,2017 265 | 263,bronze,2018 266 | 264,gold,2017 267 | 265,bronze,2014 268 | 266,bronze,2018 269 | 267,silver,2018 270 | 268,bronze,2017 271 | 269,bronze,2014 272 | 270,bronze,2014 273 | 271,silver,2018 274 | 272,inactive,2016 275 | 273,silver,2017 276 | 274,bronze,2015 277 | 275,bronze,2018 278 | 276,bronze,2017 279 | 277,bronze,2015 280 | 278,bronze,2014 281 | 279,silver,2017 282 | 280,bronze,2016 283 | 281,bronze,2018 284 | 282,silver,2018 285 | 283,silver,2014 286 | 284,bronze,2016 287 | 285,bronze,2018 288 | 286,bronze,2017 289 | 287,bronze,2018 290 | 288,bronze,2018 291 | 289,bronze,2018 292 | 290,bronze,2017 293 | 291,silver,2018 294 | 292,bronze,2018 295 | 293,silver,2018 296 | 294,gold,2018 297 | 295,inactive,2016 298 | 296,silver,2016 299 | 297,bronze,2018 300 | 298,silver,2016 301 | 299,bronze,2015 302 | 300,silver,2017 303 | 301,bronze,2015 304 | 302,bronze,2018 305 | 303,bronze,2018 306 | 304,silver,2015 307 | 305,bronze,2018 308 | 306,bronze,2017 309 | 307,bronze,2016 310 | 308,inactive,2017 311 | 309,bronze,2016 312 | 310,silver,2018 313 | 311,bronze,2018 314 | 312,bronze,2017 315 | 313,bronze,2017 316 | 314,silver,2017 317 | 315,bronze,2018 318 | 316,bronze,2014 319 | 317,bronze,2015 320 | 318,bronze,2017 321 | 319,bronze,2015 322 | 320,gold,2018 323 | 321,gold,2016 324 | 322,silver,2016 325 | 323,bronze,2017 326 | 324,bronze,2016 327 | 325,inactive,2015 328 | 326,bronze,2015 329 | 327,gold,2017 330 | 328,silver,2016 331 | 329,bronze,2018 332 | 330,bronze,2015 333 | 331,bronze,2017 334 | 332,silver,2016 335 | 333,gold,2014 336 | 334,bronze,2018 337 | 335,silver,2018 338 | 336,silver,2015 339 | 337,bronze,2018 340 | 338,bronze,2017 341 | 339,gold,2018 342 | 340,silver,2018 343 | 341,bronze,2017 344 | 342,silver,2018 345 | 343,silver,2017 346 | 344,silver,2018 347 | 345,bronze,2015 348 | 346,bronze,2018 349 | 347,silver,2018 350 | 348,inactive,2017 351 | 349,silver,2014 352 | 350,bronze,2018 353 | 351,bronze,2017 354 | 352,bronze,2017 355 | 353,inactive,2016 356 | 354,silver,2017 357 | 355,bronze,2016 358 | 356,bronze,2018 359 | 357,silver,2018 360 | 358,bronze,2017 361 | 359,gold,2014 362 | 360,bronze,2016 363 | 361,bronze,2018 364 | 362,silver,2016 365 | 363,silver,2018 366 | 364,bronze,2018 367 | 365,bronze,2018 368 | 366,bronze,2016 369 | 367,bronze,2018 370 | 368,silver,2018 371 | 369,silver,2014 372 | 370,bronze,2018 373 | 371,bronze,2018 374 | 372,bronze,2015 375 | 373,bronze,2018 376 | 374,bronze,2018 377 | 375,inactive,2016 378 | 376,silver,2017 379 | 377,silver,2018 380 | 378,bronze,2018 381 | 379,silver,2017 382 | 380,bronze,2016 383 | 381,gold,2017 384 | 382,silver,2017 385 | 383,silver,2017 386 | 384,inactive,2017 387 | 385,bronze,2017 388 | 386,silver,2015 389 | 387,silver,2018 390 | 388,bronze,2017 391 | 389,bronze,2018 392 | 390,silver,2014 393 | 391,bronze,2016 394 | 392,gold,2015 395 | 393,bronze,2016 396 | 394,bronze,2017 397 | 395,bronze,2018 398 | 396,gold,2014 399 | 397,bronze,2017 400 | 398,silver,2014 401 | 399,bronze,2015 402 | 400,bronze,2017 403 | 401,bronze,2018 404 | 402,bronze,2018 405 | 403,bronze,2018 406 | 404,bronze,2016 407 | 405,bronze,2017 408 | 406,bronze,2018 409 | 407,silver,2017 410 | 408,bronze,2018 411 | 409,bronze,2015 412 | 410,inactive,2017 413 | 411,inactive,2018 414 | 412,bronze,2017 415 | 413,silver,2017 416 | 414,silver,2017 417 | 415,bronze,2017 418 | 416,bronze,2017 419 | 417,silver,2014 420 | 418,bronze,2016 421 | 419,silver,2015 422 | 420,silver,2016 423 | 421,bronze,2018 424 | 422,silver,2018 425 | 423,bronze,2017 426 | 424,silver,2018 427 | 425,bronze,2018 428 | 426,bronze,2016 429 | 427,inactive,2016 430 | 428,silver,2018 431 | 429,bronze,2016 432 | 430,bronze,2017 433 | 431,inactive,2018 434 | 432,silver,2018 435 | 433,bronze,2018 436 | 434,gold,2018 437 | 435,gold,2017 438 | 436,silver,2017 439 | 437,silver,2014 440 | 438,bronze,2014 441 | 439,bronze,2018 442 | 440,inactive,2018 443 | 441,bronze,2017 444 | 442,gold,2018 445 | 443,inactive,2017 446 | 444,bronze,2018 447 | 445,bronze,2016 448 | 446,silver,2018 449 | 447,gold,2018 450 | 448,inactive,2017 451 | 449,bronze,2018 452 | 450,inactive,2017 453 | 451,bronze,2017 454 | 452,bronze,2017 455 | 453,silver,2016 456 | 454,bronze,2016 457 | 455,bronze,2018 458 | 456,inactive,2018 459 | 457,silver,2015 460 | 458,bronze,2017 461 | 459,bronze,2017 462 | 460,bronze,2018 463 | 461,bronze,2017 464 | 462,inactive,2017 465 | 463,bronze,2018 466 | 464,bronze,2017 467 | 465,gold,2017 468 | 466,silver,2018 469 | 467,silver,2017 470 | 468,inactive,2018 471 | 469,silver,2017 472 | 470,gold,2018 473 | 471,inactive,2018 474 | 472,gold,2014 475 | 473,bronze,2017 476 | 474,inactive,2017 477 | 475,silver,2017 478 | 476,bronze,2018 479 | 477,bronze,2018 480 | 478,gold,2014 481 | 479,inactive,2018 482 | 480,silver,2018 483 | 481,silver,2016 484 | 482,gold,2017 485 | 483,silver,2014 486 | 484,silver,2018 487 | 485,silver,2016 488 | 486,bronze,2017 489 | 487,gold,2018 490 | 488,gold,2014 491 | 489,silver,2018 492 | 490,silver,2015 493 | 491,bronze,2018 494 | 492,inactive,2018 495 | 493,bronze,2017 496 | 494,silver,2018 497 | 495,inactive,2016 498 | 496,bronze,2017 499 | 497,silver,2016 500 | 498,inactive,2017 501 | 499,bronze,2016 502 | 500,silver,2016 503 | 501,silver,2016 504 | 502,silver,2017 505 | 503,bronze,2017 506 | 504,bronze,2017 507 | 505,bronze,2018 508 | 506,bronze,2018 509 | 507,silver,2017 510 | 508,silver,2018 511 | 509,silver,2017 512 | 510,gold,2016 513 | 511,silver,2018 514 | 512,gold,2014 515 | 513,bronze,2018 516 | 514,silver,2018 517 | 515,silver,2017 518 | 516,bronze,2016 519 | 517,silver,2015 520 | 518,silver,2014 521 | 519,silver,2018 522 | 520,silver,2016 523 | 521,bronze,2017 524 | 522,bronze,2017 525 | 523,bronze,2017 526 | 524,silver,2016 527 | 525,bronze,2015 528 | 526,bronze,2015 529 | 527,bronze,2016 530 | 528,gold,2018 531 | 529,inactive,2018 532 | 530,silver,2015 533 | 531,silver,2016 534 | 532,silver,2018 535 | 533,silver,2017 536 | 534,bronze,2014 537 | 535,silver,2018 538 | 536,bronze,2018 539 | 537,bronze,2018 540 | 538,bronze,2016 541 | 539,bronze,2017 542 | 540,inactive,2017 543 | 541,silver,2016 544 | 542,bronze,2017 545 | 543,silver,2018 546 | 544,silver,2015 547 | 545,silver,2017 548 | 546,silver,2015 549 | 547,bronze,2017 550 | 548,silver,2014 551 | 549,inactive,2017 552 | 550,bronze,2017 553 | 551,bronze,2017 554 | 552,silver,2018 555 | 553,inactive,2018 556 | 554,silver,2016 557 | 555,silver,2018 558 | 556,bronze,2016 559 | 557,silver,2017 560 | 558,silver,2018 561 | 559,bronze,2016 562 | 560,silver,2016 563 | 561,silver,2016 564 | 562,silver,2017 565 | 563,silver,2016 566 | 564,inactive,2016 567 | 565,gold,2018 568 | 566,silver,2017 569 | 567,gold,2017 570 | 568,bronze,2018 571 | 569,bronze,2017 572 | 570,bronze,2018 573 | 571,silver,2015 574 | 572,bronze,2016 575 | 573,bronze,2017 576 | 574,bronze,2018 577 | 575,bronze,2017 578 | 576,silver,2018 579 | 577,bronze,2015 580 | 578,gold,2017 581 | 579,bronze,2016 582 | 580,bronze,2018 583 | 581,bronze,2014 584 | 582,silver,2018 585 | 583,gold,2017 586 | 584,silver,2018 587 | 585,silver,2018 588 | 586,silver,2014 589 | 587,gold,2017 590 | 588,bronze,2016 591 | 589,bronze,2017 592 | 590,silver,2017 593 | 591,silver,2018 594 | 592,bronze,2018 595 | 593,silver,2018 596 | 594,bronze,2014 597 | 595,silver,2018 598 | 596,silver,2017 599 | 597,bronze,2017 600 | 598,silver,2018 601 | 599,silver,2016 602 | 600,bronze,2018 603 | 601,silver,2017 604 | 602,silver,2015 605 | 603,inactive,2014 606 | 604,bronze,2018 607 | 605,bronze,2017 608 | 606,gold,2017 609 | 607,silver,2015 610 | 608,bronze,2018 611 | 609,bronze,2017 612 | 610,silver,2015 613 | 611,silver,2018 614 | 612,bronze,2018 615 | 613,bronze,2016 616 | 614,inactive,2018 617 | 615,bronze,2017 618 | 616,bronze,2015 619 | 617,bronze,2016 620 | 618,bronze,2017 621 | 619,silver,2017 622 | 620,silver,2018 623 | 621,silver,2018 624 | 622,bronze,2018 625 | 623,bronze,2018 626 | 624,silver,2018 627 | 625,bronze,2014 628 | 626,silver,2016 629 | 627,bronze,2016 630 | 628,bronze,2018 631 | 629,bronze,2018 632 | 630,silver,2018 633 | 631,bronze,2018 634 | 632,bronze,2018 635 | 633,silver,2016 636 | 634,inactive,2017 637 | 635,inactive,2018 638 | 636,bronze,2018 639 | 637,bronze,2016 640 | 638,bronze,2017 641 | 639,bronze,2017 642 | 640,silver,2015 643 | 641,bronze,2014 644 | 642,bronze,2017 645 | 643,bronze,2017 646 | 644,bronze,2017 647 | 645,bronze,2016 648 | 646,bronze,2018 649 | 647,bronze,2018 650 | 648,bronze,2014 651 | 649,gold,2018 652 | 650,bronze,2017 653 | 651,bronze,2016 654 | 652,bronze,2014 655 | 653,silver,2016 656 | 654,bronze,2018 657 | 655,bronze,2015 658 | 656,silver,2016 659 | 657,bronze,2015 660 | 658,silver,2014 661 | 659,bronze,2017 662 | 660,silver,2017 663 | 661,silver,2016 664 | 662,inactive,2016 665 | 663,bronze,2018 666 | 664,bronze,2015 667 | 665,silver,2015 668 | 666,bronze,2018 669 | 667,gold,2018 670 | 668,silver,2017 671 | 669,bronze,2017 672 | 670,silver,2016 673 | 671,bronze,2017 674 | 672,inactive,2017 675 | 673,bronze,2017 676 | 674,silver,2017 677 | 675,bronze,2018 678 | 676,silver,2018 679 | 677,inactive,2017 680 | 678,silver,2016 681 | 679,silver,2018 682 | 680,bronze,2017 683 | 681,bronze,2015 684 | 682,inactive,2015 685 | 683,bronze,2015 686 | 684,silver,2015 687 | 685,bronze,2017 688 | 686,silver,2018 689 | 687,silver,2016 690 | 688,bronze,2016 691 | 689,bronze,2018 692 | 690,bronze,2017 693 | 691,gold,2015 694 | 692,bronze,2014 695 | 693,inactive,2016 696 | 694,silver,2018 697 | 695,silver,2015 698 | 696,bronze,2017 699 | 697,silver,2018 700 | 698,bronze,2017 701 | 699,gold,2016 702 | 700,inactive,2016 703 | 701,gold,2018 704 | 702,silver,2016 705 | 703,bronze,2014 706 | 704,bronze,2018 707 | 705,silver,2014 708 | 706,bronze,2017 709 | 707,bronze,2018 710 | 708,bronze,2018 711 | 709,bronze,2018 712 | 710,bronze,2016 713 | 711,silver,2014 714 | 712,bronze,2017 715 | 713,bronze,2017 716 | 714,bronze,2015 717 | 715,bronze,2018 718 | 716,bronze,2018 719 | 717,bronze,2017 720 | 718,silver,2017 721 | 719,bronze,2015 722 | 720,silver,2018 723 | 721,bronze,2018 724 | 722,bronze,2018 725 | 723,bronze,2014 726 | 724,bronze,2018 727 | 725,silver,2018 728 | 726,gold,2014 729 | 727,inactive,2015 730 | 728,silver,2018 731 | 729,silver,2018 732 | 730,bronze,2016 733 | 731,inactive,2017 734 | 732,silver,2017 735 | 733,inactive,2018 736 | 734,silver,2017 737 | 735,bronze,2018 738 | 736,bronze,2018 739 | 737,bronze,2018 740 | 738,silver,2017 741 | 739,silver,2018 742 | 740,bronze,2018 743 | 741,silver,2015 744 | 742,bronze,2016 745 | 743,bronze,2017 746 | 744,bronze,2018 747 | 745,bronze,2017 748 | 746,silver,2015 749 | 747,bronze,2018 750 | 748,inactive,2017 751 | 749,silver,2017 752 | 750,bronze,2016 753 | 751,inactive,2018 754 | 752,silver,2018 755 | 753,bronze,2017 756 | 754,silver,2017 757 | 755,silver,2018 758 | 756,bronze,2018 759 | 757,silver,2014 760 | 758,bronze,2017 761 | 759,gold,2017 762 | 760,inactive,2016 763 | 761,silver,2017 764 | 762,bronze,2015 765 | 763,silver,2017 766 | 764,silver,2017 767 | 765,inactive,2018 768 | 766,bronze,2018 769 | 767,inactive,2014 770 | 768,bronze,2017 771 | 769,silver,2017 772 | 770,silver,2017 773 | 771,bronze,2018 774 | 772,bronze,2018 775 | 773,silver,2017 776 | 774,bronze,2017 777 | 775,bronze,2018 778 | 776,silver,2015 779 | 777,bronze,2018 780 | 778,bronze,2014 781 | 779,silver,2018 782 | 780,bronze,2017 783 | 781,bronze,2018 784 | 782,bronze,2018 785 | 783,silver,2018 786 | 784,silver,2017 787 | 785,silver,2018 788 | 786,silver,2015 789 | 787,bronze,2018 790 | 788,silver,2016 791 | 789,silver,2018 792 | 790,bronze,2018 793 | 791,silver,2017 794 | 792,silver,2017 795 | 793,bronze,2017 796 | 794,bronze,2018 797 | 795,gold,2018 798 | 796,bronze,2015 799 | 797,gold,2018 800 | 798,bronze,2018 801 | 799,bronze,2018 802 | 800,silver,2018 803 | 801,bronze,2017 804 | 802,silver,2017 805 | 803,silver,2018 806 | 804,bronze,2018 807 | 805,silver,2017 808 | 806,bronze,2016 809 | 807,inactive,2016 810 | 808,silver,2015 811 | 809,silver,2017 812 | 810,bronze,2018 813 | 811,bronze,2016 814 | 812,bronze,2017 815 | 813,silver,2014 816 | 814,silver,2018 817 | 815,gold,2017 818 | 816,bronze,2018 819 | 817,silver,2018 820 | 818,bronze,2015 821 | 819,gold,2018 822 | 820,silver,2018 823 | 821,bronze,2017 824 | 822,bronze,2015 825 | 823,bronze,2018 826 | 824,silver,2017 827 | 825,gold,2017 828 | 826,bronze,2014 829 | 827,bronze,2015 830 | 828,bronze,2018 831 | 829,silver,2017 832 | 830,silver,2017 833 | 831,gold,2018 834 | 832,silver,2017 835 | 833,bronze,2017 836 | 834,silver,2018 837 | 835,inactive,2017 838 | 836,bronze,2015 839 | 837,bronze,2018 840 | 838,gold,2015 841 | 839,gold,2016 842 | 840,bronze,2018 843 | 841,bronze,2017 844 | 842,silver,2017 845 | 843,silver,2018 846 | 844,bronze,2017 847 | 845,silver,2017 848 | 846,inactive,2016 849 | 847,silver,2018 850 | 848,silver,2018 851 | 849,bronze,2017 852 | 850,gold,2015 853 | 851,bronze,2018 854 | 852,inactive,2018 855 | 853,inactive,2018 856 | 854,bronze,2016 857 | 855,bronze,2015 858 | 856,silver,2018 859 | 857,bronze,2018 860 | 858,bronze,2018 861 | 859,bronze,2016 862 | 860,silver,2018 863 | 861,bronze,2018 864 | 862,bronze,2018 865 | 863,silver,2017 866 | 864,silver,2018 867 | 865,inactive,2018 868 | 866,inactive,2017 869 | 867,silver,2014 870 | 868,silver,2014 871 | 869,gold,2018 872 | 870,inactive,2018 873 | 871,gold,2016 874 | 872,bronze,2018 875 | 873,silver,2018 876 | 874,silver,2016 877 | 875,silver,2017 878 | 876,bronze,2016 879 | 877,bronze,2018 880 | 878,bronze,2014 881 | 879,inactive,2017 882 | 880,bronze,2017 883 | 881,gold,2017 884 | 882,silver,2016 885 | 883,bronze,2016 886 | 884,inactive,2016 887 | 885,bronze,2017 888 | 886,silver,2018 889 | 887,inactive,2016 890 | 888,silver,2018 891 | 889,bronze,2017 892 | 890,silver,2018 893 | 891,bronze,2015 894 | 892,inactive,2018 895 | 893,bronze,2014 896 | 894,silver,2014 897 | 895,bronze,2017 898 | 896,gold,2014 899 | 897,bronze,2018 900 | 898,inactive,2018 901 | 899,silver,2014 902 | 900,bronze,2015 903 | 901,bronze,2018 904 | 902,bronze,2014 905 | 903,bronze,2016 906 | 904,bronze,2014 907 | 905,bronze,2018 908 | 906,silver,2017 909 | 907,inactive,2015 910 | 908,inactive,2015 911 | 909,gold,2018 912 | 910,bronze,2017 913 | 911,bronze,2018 914 | 912,gold,2017 915 | 913,bronze,2018 916 | 914,bronze,2018 917 | 915,inactive,2014 918 | 916,silver,2017 919 | 917,silver,2017 920 | 918,silver,2018 921 | 919,gold,2017 922 | 920,bronze,2016 923 | 921,gold,2017 924 | 922,silver,2018 925 | 923,silver,2016 926 | 924,bronze,2017 927 | 925,bronze,2015 928 | 926,bronze,2017 929 | 927,bronze,2018 930 | 928,bronze,2016 931 | 929,bronze,2014 932 | 930,bronze,2018 933 | 931,gold,2018 934 | 932,silver,2014 935 | 933,silver,2017 936 | 934,bronze,2018 937 | 935,inactive,2018 938 | 936,inactive,2018 939 | 937,inactive,2018 940 | 938,bronze,2017 941 | 939,bronze,2016 942 | 940,gold,2014 943 | 941,bronze,2014 944 | 942,silver,2018 945 | 943,bronze,2018 946 | 944,bronze,2017 947 | 945,silver,2017 948 | 946,silver,2018 949 | 947,silver,2016 950 | 948,bronze,2018 951 | 949,inactive,2016 952 | 950,bronze,2017 953 | 951,bronze,2016 954 | 952,gold,2018 955 | 953,bronze,2017 956 | 954,bronze,2016 957 | 955,gold,2017 958 | 956,silver,2016 959 | 957,silver,2018 960 | 958,bronze,2016 961 | 959,bronze,2015 962 | 960,bronze,2018 963 | 961,bronze,2018 964 | 962,silver,2018 965 | 963,bronze,2018 966 | 964,silver,2017 967 | 965,inactive,2015 968 | 966,bronze,2018 969 | 967,bronze,2018 970 | 968,bronze,2018 971 | 969,silver,2018 972 | 970,bronze,2017 973 | 971,bronze,2018 974 | 972,bronze,2018 975 | 973,bronze,2017 976 | 974,bronze,2018 977 | 975,silver,2018 978 | 976,silver,2017 979 | 977,silver,2014 980 | 978,gold,2015 981 | 979,bronze,2018 982 | 980,silver,2014 983 | 981,bronze,2017 984 | 982,bronze,2015 985 | 983,bronze,2018 986 | 984,silver,2017 987 | 985,inactive,2018 988 | 986,bronze,2018 989 | 987,gold,2016 990 | 988,bronze,2015 991 | 989,bronze,2015 992 | 990,silver,2017 993 | 991,silver,2016 994 | 992,silver,2014 995 | 993,gold,2017 996 | 994,bronze,2018 997 | 995,bronze,2016 998 | 996,bronze,2018 999 | 997,bronze,2018 1000 | 998,bronze,2017 1001 | 999,silver,2014 1002 | -------------------------------------------------------------------------------- /Ch02/generateAggregateData.py: -------------------------------------------------------------------------------- 1 | ### code to generate the data set 2 | import pdb 3 | import numpy as np 4 | import pandas as pd 5 | 6 | ## membership status 7 | years = ['2014', '2015', '2016', '2017', '2018'] 8 | userStatus = ['bronze', 'silver', 'gold', 'inactive'] 9 | 10 | userYears = np.random.choice(years, 1000, p = [0.1, 0.1, 0.15, 0.30, 0.35]) 11 | userStats = np.random.choice(userStatus, 1000, p = [0.5, 0.3, 0.1, 0.1]) 12 | 13 | yearJoined = pd.DataFrame({'yearJoined': userYears, 14 | 'userStats': userStats}) 15 | 16 | ## email behavior 17 | NUM_EMAILS_SENT_WEEKLY = 3 18 | 19 | ## types of behavior 20 | def never_opens(period_rng): 21 | return [] 22 | 23 | def constant_open_rate(period_rng): 24 | n, p = NUM_EMAILS_SENT_WEEKLY, np.random.uniform(0, 1) 25 | num_opened = np.random.binomial(n, p, len(period_rng)) 26 | return num_opened 27 | 28 | def open_rate_with_factor_change(period_rng, fac): 29 | 30 | if len(period_rng) < 1 : 31 | return [] 32 | 33 | times = np.random.randint(0, len(period_rng), int(0.1 * len(period_rng))) 34 | try: 35 | n, p = NUM_EMAILS_SENT_WEEKLY, np.random.uniform(0, 1) 36 | num_opened = np.zeros(len(period_rng)) 37 | for pd in range(0, len(period_rng), 2): 38 | num_opened[pd:(pd + 2)] = np.random.binomial(n, p, 2) 39 | p = max(min(1, p * fac), 0) 40 | except: 41 | num_opened[pd] = np.random.binomial(n, p, 1) 42 | for t in times: 43 | num_opened[t] = 0 44 | return num_opened 45 | 46 | def increasing_open_rate(period_rng): 47 | return open_rate_with_factor_change(period_rng, np.random.uniform(1.01, 1.30)) 48 | 49 | def decreasing_open_rate(period_rng): 50 | return open_rate_with_factor_change(period_rng, np.random.uniform(0.5, 0.99)) 51 | 52 | def random_weekly_time_delta(): 53 | days_of_week = [d for d in range(7)] 54 | hours_of_day = [h for h in range(11, 23)] 55 | minute_of_hour = [m for m in range(60)] 56 | second_of_minute = [s for s in range(60)] 57 | return pd.Timedelta(str(np.random.choice(days_of_week)) + " days" ) + \ 58 | pd.Timedelta(str(np.random.choice(hours_of_day)) + " hours" ) + \ 59 | pd.Timedelta(str(np.random.choice(minute_of_hour)) + " minutes") + \ 60 | pd.Timedelta(str(np.random.choice(second_of_minute)) + " seconds") 61 | 62 | ## donation behavior 63 | def produce_donations(period_rng, user_behavior, num_emails, use_id, user_join_year): 64 | donation_amounts = np.array([0, 25, 50, 75, 100, 250, 500, 1000, 1500, 2000]) 65 | user_has = np.random.choice(donation_amounts) 66 | 67 | user_gives = num_emails / (NUM_EMAILS_SENT_WEEKLY * len(period_rng)) * user_has 68 | user_gives_idx = np.where(user_gives >= donation_amounts)[0][-1] 69 | user_gives_idx = max(min(user_gives_idx, len(donation_amounts) - 2), 1) 70 | 71 | num_times_gave = np.random.poisson(2) * (2018 - user_join_year) 72 | 73 | times = np.random.randint(0, len(period_rng), num_times_gave) 74 | 75 | donations = pd.DataFrame({'user': [], 'amount': [], 'timestamp': []}) 76 | for n in range(num_times_gave): 77 | 78 | donations = donations.append(pd.DataFrame({'user': [use_id], 79 | 'amount': [donation_amounts[user_gives_idx + \ 80 | np.random.binomial(1, .3)]], 81 | 'timestamp': [str(period_rng[times[n]].start_time + random_weekly_time_delta())]})) 82 | 83 | if donations.shape[0] > 0: 84 | donations = donations[donations.amount != 0] 85 | return donations 86 | 87 | 88 | ## run it 89 | behaviors = [never_opens, constant_open_rate, increasing_open_rate, decreasing_open_rate] 90 | user_behaviors = np.random.choice(behaviors, 1000, [0.2, 0.5, 0.1, 0.2]) 91 | 92 | rng = pd.period_range('2015-02-14', '2018-06-01', freq = 'W') 93 | emails = pd.DataFrame({'user': [], 'week': [], 'emailsOpened':[]}) 94 | donations = pd.DataFrame({'user': [], 'amount': [], 'timestamp': []}) 95 | 96 | for idx in range(yearJoined.shape[0]): 97 | ## randomly generate the date when a user would have joined 98 | join_date = pd.Timestamp(yearJoined.iloc[idx].yearJoined) + \ 99 | pd.Timedelta(str(np.random.randint(0, 365)) + ' days') 100 | join_date = min(join_date, pd.Timestamp('2018-06-01')) 101 | 102 | ## user should not receive emails or make donations before joining 103 | ## thank you to Murray M Gillin for reporting errata and suggesting this correction 104 | user_rng = rng[rng.start_time > join_date] 105 | 106 | if len(user_rng) < 1: 107 | continue 108 | 109 | info = user_behaviors[idx](user_rng) 110 | 111 | if len(info) == len(user_rng): 112 | emails = emails.append(pd.DataFrame({'user': [idx] * len(info), 113 | 'week': [str(r.start_time) for r in user_rng], 114 | 'emailsOpened': info})) 115 | 116 | donations = donations.append(produce_donations(user_rng, user_behaviors[idx], 117 | sum(info), idx, join_date.year)) 118 | 119 | 120 | 121 | ## get rid of zero donations and zero emails 122 | emails = emails[emails.emailsOpened != 0] 123 | yearJoined.index.name = 'user' 124 | 125 | yearJoined.to_csv('data/year_joined.csv', index = False) 126 | donations.to_csv( 'data/donations.csv', index = False) 127 | emails.to_csv( 'data/emails.csv', index = False) 128 | 129 | 130 | -------------------------------------------------------------------------------- /Ch02/missing.R: -------------------------------------------------------------------------------- 1 | require(zoo) 2 | require(data.table) 3 | 4 | unemp <- fread("data/UNRATE.csv") 5 | unemp[, DATE := as.Date(DATE)] 6 | setkey(unemp, DATE) 7 | 8 | ## generate a data set where data is randomly missing 9 | rand.unemp.idx <- sample(1:nrow(unemp), .1*nrow(unemp)) 10 | rand.unemp <- unemp[-rand.unemp.idx] 11 | 12 | ## generate a data set where data is more likely to be missing if it's high 13 | high.unemp.idx <- which(unemp$UNRATE > 8) 14 | high.unemp.idx <- sample(high.unemp.idx, .5 * length(high.unemp.idx)) 15 | bias.unemp <- unemp[-high.unemp.idx] 16 | 17 | 18 | ## we will use data.table's rolling joins in the cases with missing data to identify the missing data 19 | all.dates <- seq(from = unemp$DATE[1], to = tail(unemp$DATE, 1), by = "months") 20 | 21 | rand.unemp = rand.unemp[J(all.dates), roll=0] 22 | bias.unemp = bias.unemp[J(all.dates), roll=0] 23 | 24 | rand.unemp[, rpt := is.na(UNRATE)] 25 | 26 | ## forward filling 27 | rand.unemp[, impute.ff := na.locf(UNRATE, na.rm = FALSE)] 28 | bias.unemp[, impute.ff := na.locf(UNRATE, na.rm = FALSE)] 29 | 30 | ## to plot a sample graph showing the flat portions 31 | png("ffplot.png") 32 | unemp[350:400, plot(DATE, UNRATE, col = 1, type = 'b')] 33 | rand.unemp[350:400, lines(DATE, impute.ff, col = 2)] 34 | rand.unemp[350:400][rpt == TRUE, points(DATE, impute.ff, col = 2, lwd = 3)] 35 | dev.off() 36 | 37 | ## rolling mean with a lookahead 38 | rand.unemp[, impute.rm.nolookahead := rollapply(c(NA, UNRATE, NA), 3, 39 | function(x) { 40 | if (!is.na(x[1])) x[1] else mean(x, na.rm = TRUE) 41 | })] 42 | bias.unemp[, impute.rm.nolookahead := rollapply(c(NA, UNRATE, NA), 3, 43 | function(x) { 44 | if (!is.na(x[1])) x[1] else mean(x, na.rm = TRUE) 45 | })] 46 | 47 | ## rolling mean without a lookahead 48 | rand.unemp[, impute.rm.lookahead := rollapply(c(NA, NA, UNRATE), 3, 49 | function(x) { 50 | if (!is.na(x[3])) x[3] else mean(x, na.rm = TRUE) 51 | })] 52 | bias.unemp[, impute.rm.lookahead := rollapply(c(NA, NA, UNRATE), 3, 53 | function(x) { 54 | if (!is.na(x[3])) x[3] else mean(x, na.rm = TRUE) 55 | })] 56 | 57 | ## to plot a sample graph showing the flat portions 58 | png("maplot.png") 59 | use.idx = 150:200 60 | unemp[use.idx, plot(DATE, UNRATE, col = 1, type = 'b')] 61 | rand.unemp[use.idx, lines(DATE, impute.rm.nolookahead, col = 2)] 62 | rand.unemp[use.idx][rpt == TRUE, points(DATE, impute.rm.nolookahead, col = 2, lwd = 3)] 63 | rand.unemp[use.idx, lines(DATE, impute.rm.lookahead, col = 3)] 64 | rand.unemp[use.idx][rpt == TRUE, points(DATE, impute.rm.lookahead, col = 3, lwd = 3)] 65 | dev.off() 66 | 67 | 68 | 69 | ## linear interpolation 70 | rand.unemp[, impute.li := na.approx(UNRATE)] 71 | bias.unemp[, impute.li := na.approx(UNRATE)] 72 | 73 | ## polynomial interpolation 74 | rand.unemp[, impute.sp := na.spline(UNRATE)] 75 | bias.unemp[, impute.sp := na.spline(UNRATE)] 76 | 77 | png("splineplot.png") 78 | use.idx = 650:680 79 | unemp[use.idx, plot(DATE, UNRATE, col = 1, type = 'b')] 80 | rand.unemp[use.idx, lines(DATE, impute.li, col = 2)] 81 | rand.unemp[use.idx][rpt == TRUE, points(DATE, impute.li, col = 2, lwd = 3)] 82 | rand.unemp[use.idx, lines(DATE, impute.sp, col = 3)] 83 | rand.unemp[use.idx][rpt == TRUE, points(DATE, impute.sp, col = 3, lwd = 3)] 84 | dev.off() 85 | 86 | 87 | ## we can compare the sum square difference for each method to the true values 88 | sort(rand.unemp[ , lapply(.SD, function(x) mean((x - unemp$UNRATE)^2, na.rm = TRUE)), 89 | .SDcols = c("impute.ff", "impute.rm.nolookahead", "impute.rm.lookahead", "impute.li", "impute.sp")]) 90 | 91 | sort(bias.unemp[ , lapply(.SD, function(x) mean((x - unemp$UNRATE)^2, na.rm = TRUE)), 92 | .SDcols = c("impute.ff", "impute.rm.nolookahead", "impute.rm.lookahead", "impute.li", "impute.sp")]) 93 | 94 | 95 | 96 | smoothed = unemp[, HoltWinters(UNRATE, alpha = 0.1, beta = FALSE, gamma = FALSE)] 97 | plot(unemp$UNRATE, lty = 4, lwd = 1, type = 'l') 98 | lines(smoothed$fitted[, "xhat"], lty = 2, lwd = 2) 99 | 100 | 101 | 102 | air.passengers = fread("data/AirPassengers.csv") 103 | air.passengers[, V1 := as.Date(V1, format = "%Y-%m")] 104 | data = as.ts(air.passengers$V2, deltat = 1/2) 105 | 106 | -------------------------------------------------------------------------------- /Ch02/smooth.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | air = pd.read_csv('data/AirPassengers.csv', parse_dates = True, header = None) 4 | air.columns = ['Date', 'Passengers'] 5 | 6 | ## thanks to Mark Wilson for this code correction 7 | air['Smooth.5'] = air.ewm(alpha=0.5).mean().Passengers 8 | air['Smooth.1'] = air.ewm(alpha=0.1,).mean().Passengers 9 | air['Smooth.9'] = air.ewm(alpha=0.9,).mean().Passengers 10 | -------------------------------------------------------------------------------- /Ch02/smoothing.R: -------------------------------------------------------------------------------- 1 | require(data.table) 2 | 3 | air = fread('data/AirPassengers.csv') 4 | names(air) = c("Date", "Num") 5 | air[, Date:= as.Date(paste0(Date, "-01"), format = "%Y-%m-%d")] 6 | 7 | ## loess smoothing 8 | loess.smooth(air$Date, air$Num) 9 | -------------------------------------------------------------------------------- /Ch02/timeZones.R: -------------------------------------------------------------------------------- 1 | require(lubridate) 2 | 3 | ## Creating a timestamp with a time zone 4 | eventTime <- as.POSIXct("2018-02-06 15:41:23.102") 5 | 6 | ## > eventTime 7 | ## [1] "2018-02-06 15:41:23 EST" 8 | 9 | eventTime1 <- as.POSIXct("2018-02-06 15:41:23.102", tz="EST") 10 | ## but 11 | eventTime2 <- as.POSIXct("2018-02-06 15:41:23.102", tz="EE") 12 | eventTime3 <- as.POSIXct("2018-02-06 15:41:23.102") 13 | 14 | attr(eventTime1,"tzone") 15 | attr(eventTime2,"tzone") 16 | attr(eventTime3,"tzone") 17 | 18 | 19 | format(eventTime, tz="GMT",usetz=TRUE) 20 | format(eventTime, tz="America/Los_Angeles",usetz=TRUE) 21 | 22 | ## > attr(eventTime,"tzone") 23 | ## [1] "EST" 24 | ## > attr(eventTime2,"tzone") 25 | ## [1] "EE" 26 | ## > 27 | 28 | ## Converting time from one time zone to another 29 | ## Need to remove time zone via passing back to a string 30 | ## Note it's ugly but you can easily wrap it in a function and drop it in your .Rprofile 31 | eventTime1Converted <- as.POSIXct(format(eventTime1, tz = "GMT", usetz = TRUE), tz = "GMT") 32 | 33 | ## or 34 | eventTime1Copy <- eventTime1 35 | attributes(eventTime1Copy)$tzone <- "GMT" 36 | ## eventTime1Copy == eventTime1 37 | ## [1] TRUE 38 | 39 | 40 | ## ## What is going on here? 41 | ## > eventTime1Converted <= eventTime1 42 | ## [1] TRUE 43 | ## > eventTime1Converted >= eventTime1 44 | ## [1] FALSE 45 | ## > 46 | 47 | ## > eventTime1 == eventTime1Converted 48 | ## [1] FALSE 49 | ## depends on == implementation 50 | 51 | ## > as.numeric(eventTime1) 52 | ## [1] 1517949683 53 | ## > as.numeric(eventTime1Copy) 54 | ## [1] 1517949683 55 | ## > as.numeric(eventTime1Copy) == as.numeric(eventTime1) 56 | ## [1] TRUE 57 | ## > 58 | 59 | ## Calculating time difference between time zones 60 | eventTime1 - eventTime 61 | ## > eventTime1 - eventTime 62 | ## Time difference of 0 secs 63 | 64 | eventTime1 - with_tz(eventTime1, "GMT") 65 | ## > eventTime1 - with_tz(eventTime1, "GMT") 66 | ## Time difference of 0 secs 67 | 68 | t1 <- as.POSIXct("2018-02-06 15:41:23.102", tz="EST") 69 | t2 <- as.POSIXct("2018-02-06 15:41:23.102", tz="GMT") 70 | 71 | difftime(t1, t2, units = "hours") 72 | difftime(t1, t2, units = "days") 73 | 74 | 75 | ## Setting up your system, consider this for your R profile 76 | Sys.setenv(TZ="GMT") 77 | 78 | ## A little lubridate 79 | 80 | 81 | ## Converting time from one time zone to another while keeping the underlying moment in time the same 82 | with_tz(eventTime1, "GMT") 83 | ## with_tz(eventTime1, "GMT") == eventTime1 84 | ## [1] TRUE 85 | ## > 86 | 87 | ## You can also keep the 'label' on the time and simply swap the time zone 88 | force_tz(eventTime1, "GMT") 89 | ## > force_tz(eventTime1, "GMT") == eventTime1 90 | ## [1] FALSE (of course no) 91 | 92 | 93 | ## R: 94 | 95 | ## Base R is fairly savvy in its handling of time related data, and for this reason you will generally get time with a timestamp when you are generating time from the system information. For example, Sys.time() will return a POSIXlt with a timezone. 96 | 97 | ## “There are two POSIXt types, POSIXct and POSIXlt. "ct" can stand for calendar time, it stores the number of seconds since the origin. "lt", or local time, keeps the date as a list of time attributes (such as "hour" and "mon").” If you are working with data that relates to human behavior, you likely want to use the “lt” variant because you will care about human related time labels, such as day of the week, but if you are working with scientific data where such labels are unlikely to be important, the POSIXct variant is more lightweight. 98 | 99 | ## Note that operating systems are not built into R but rather rely on the underlying time zones stored and used by the operating system. For that reason, the exact abbreviations for time zones, how far back in time they go, and their underlying representation will depend on your operating system. You can see your system’s timezone with Sys.timezone(), or you can see and set this variable with the TZ environmental variable. You can hence always have the preferred timezone by running a command to set Sys.setenv() or the Renviron.site variable. For this reason, the rules implementing time zones and daylight savings are done by your operating system, which means a change or upgrade to your operating system can result in display changes to your time related variables in some cases. 100 | -------------------------------------------------------------------------------- /Ch02/timeZones.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import pytz 3 | 4 | datetime.datetime.utcnow() 5 | # datetime.datetime.utcnow() 6 | # datetime.datetime(2018, 5, 31, 14, 49, 43, 187680) 7 | 8 | datetime.datetime.now() 9 | # >>> >>> datetime.datetime.now() 10 | # datetime.datetime(2018, 5, 31, 10, 49, 59, 984947) 11 | # as we can see, my computer does not return UTC even though there is no time zone attached 12 | 13 | datetime.datetime.now(datetime.timezone.utc) 14 | # >>> datetime.datetime.now(datetime.timezone.utc) 15 | # datetime.datetime(2018, 5, 31, 14, 51, 35, 601355, tzinfo=datetime.timezone.utc) 16 | 17 | 18 | western = pytz.timezone('US/Pacific') 19 | western.zone 20 | # >>> eastern.zone 21 | # 'US/Pacific' 22 | 23 | ## the API supports two ways of building a time zone aware time, either via 'localize' or to convert a timezone from one locale to another 24 | # here we localize 25 | loc_dt = western.localize(datetime.datetime(2018, 5, 15, 12, 34, 0)) 26 | # datetime.datetime(2018, 5, 15, 12, 34, tzinfo=) 27 | # >>> 28 | 29 | london_tz = pytz.timezone('Europe/London') 30 | london_dt = loc_dt.astimezone(london_tz) 31 | # >>> london_dt 32 | # datetime.datetime(2018, 5, 15, 20, 34, tzinfo=) 33 | f = '%Y-%m-%d %H:%M:%S %Z%z' 34 | datetime.datetime(2018, 5, 12, 12, 15, 0, tzinfo = london_tz).strftime(f) 35 | ## '2018-05-12 12:15:00 LMT-0001' 36 | ## as highlighted in the pytz documentation using the tzinfo of the datetime.datetime initializer does not always lead to the desired outcome 37 | ## such as with the London 38 | ## according to the pytz documentation, this method does lead to the desired results in time zones without daylight savings 39 | 40 | # generally you want to store data in UTC and convert only when generating human readable output 41 | # you can also do date arithmetic with time zones 42 | event1 = datetime.datetime(2018, 5, 12, 12, 15, 0, tzinfo = london_tz) 43 | event2 = datetime.datetime(2018, 5, 13, 9, 15, 0, tzinfo = western) 44 | event2 - event1 45 | ## this will yield the wrong time delta because the time zones haven't been labelled properly 46 | 47 | 48 | event1 = london_tz.localize( datetime.datetime(2018, 5, 12, 12, 15, 0)) 49 | event2 = western.localize(datetime.datetime(2018, 5, 13, 9, 15, 0)) 50 | event2 - event1 51 | 52 | 53 | 54 | event1 = london_tz.localize((datetime.datetime(2018, 5, 12, 12, 15, 0))).astimezone(datetime.timezone.utc) 55 | event2 = western.localize(datetime.datetime(2018, 5, 13, 9, 15, 0)).astimezone(datetime.timezone.utc) 56 | event2 - event1 57 | 58 | ## note that in the event you are working on dates for arithmetic that could corss daylight savings time boundaries 59 | ## you also need to apply the normalize function for your time zone 60 | event1 = london_tz.localize( datetime.datetime(2018, 5, 12, 12, 15, 0)) 61 | event2 = western.localize(datetime.datetime(2018, 5, 13, 9, 15, 0)) 62 | 63 | ## have a look at pytz.common_timezones 64 | pytz.common_timezones 65 | ## or country specific 66 | pytz.country_timezones('RU') 67 | # >>> pytz.country_timezones('RU') 68 | # ['Europe/Kaliningrad', 'Europe/Moscow', 'Europe/Simferopol', 'Europe/Volgograd', 'Europe/Kirov', 'Europe/Astrakhan', 'Europe/Saratov', 'Europe/Ulyanovsk', 'Europe/Samara', 'Asia/Yekaterinburg', 'Asia/Omsk', 'Asia/Novosibirsk', 'Asia/Barnaul', 'Asia/Tomsk', 'Asia/Novokuznetsk', 'Asia/Krasnoyarsk', 'Asia/Irkutsk', 'Asia/Chita', 'Asia/Yakutsk', 'Asia/Khandyga', 'Asia/Vladivostok', 'Asia/Ust-Nera', 'Asia/Magadan', 'Asia/Sakhalin', 'Asia/Srednekolymsk', 'Asia/Kamchatka', 'Asia/Anadyr'] 69 | # >>> 70 | # >>> pytz.country_timezones('fr') 71 | # ['Europe/Paris'] 72 | # >>> 73 | 74 | 75 | ## time zones 76 | ambig_time = western.localize(datetime.datetime(2002, 10, 27, 1, 30, 00)).astimezone(datetime.timezone.utc) 77 | ambig_time_earlier = ambig_time - datetime.timedelta(hours=1) 78 | ambig_time_later = ambig_time + datetime.timedelta(hours=1) 79 | ambig_time_earlier.astimezone(western) 80 | ambig_time.astimezone(western) 81 | ambig_time_later.astimezone(western) 82 | # >>> >>> >>> datetime.datetime(2002, 10, 27, 1, 30, tzinfo=) 83 | # >>> datetime.datetime(2002, 10, 27, 1, 30, tzinfo=) 84 | # >>> datetime.datetime(2002, 10, 27, 2, 30, tzinfo=) 85 | # >>> >>> 86 | # notice that the last two timestamps are identical, no good! 87 | 88 | ## in this case you need to use is_dst to indicate whether daylight savings is in effect 89 | ambig_time = western.localize(datetime.datetime(2002, 10, 27, 1, 30, 00), is_dst = True).astimezone(datetime.timezone.utc) 90 | ambig_time_earlier = ambig_time - datetime.timedelta(hours=1) 91 | ambig_time_later = ambig_time + datetime.timedelta(hours=1) 92 | ambig_time_earlier.astimezone(western) 93 | ambig_time.astimezone(western) 94 | ambig_time_later.astimezone(western) 95 | # >> >>> datetime.datetime(2002, 10, 27, 0, 30, tzinfo=) 96 | # >>> datetime.datetime(2002, 10, 27, 1, 30, tzinfo=) 97 | # >>> datetime.datetime(2002, 10, 27, 1, 30, tzinfo=) 98 | 99 | 100 | ## notice that now we don't have the same time happening twice. 101 | ## it may appear that way until you check the offset from UTC 102 | loc_dt.strftime(f) 103 | -------------------------------------------------------------------------------- /Ch03/acf.R: -------------------------------------------------------------------------------- 1 | ## R uses radians so to set frequency we'll do radians 2 | 3 | x = 1:100 4 | 5 | ## Noiseless series 6 | y = sin(x * pi / 4) 7 | plot(y, type = 'b') 8 | acf(y) 9 | pacf(y) 10 | 11 | y = sin(x * pi / 10) 12 | plot(y, type = 'b') 13 | acf(y) 14 | pacf(y) 15 | 16 | y = sin(x * pi / 4) + sin(x * pi / 10) 17 | plot(y, type = 'b') 18 | acf(y) 19 | pacf(y) 20 | 21 | par(mfrow = c(3, 3)) 22 | ## Somewhat noisy series 23 | noise1 = rnorm(100, sd = 0.05) 24 | noise2 = rnorm(100, sd = 0.05) 25 | par(mfrow = c(3, 3)) 26 | y = sin(x * pi / 4) + noise1 27 | plot(y, type = 'b') 28 | acf(y) 29 | pacf(y) 30 | 31 | y = sin(x * pi / 10) + noise2 32 | plot(y, type = 'b') 33 | acf(y) 34 | pacf(y) 35 | 36 | y = sin(x * pi / 4) + sin(x * pi / 10) + noise1 + noise2 37 | plot(y, type = 'b') 38 | acf(y) 39 | pacf(y) 40 | 41 | ## Very noisy series 42 | noise1 = rnorm(100, sd = 0.3) 43 | noise2 = rnorm(100, sd = 0.3) 44 | par(mfrow = c(3, 3)) 45 | y = sin(x * pi / 4) + noise1 46 | plot(y, type = 'b') 47 | acf(y) 48 | pacf(y) 49 | 50 | y = sin(x * pi / 10) + noise2 51 | plot(y, type = 'b') 52 | acf(y) 53 | pacf(y) 54 | 55 | y = sin(x * pi / 4) + sin(x * pi / 10) + noise1 + noise2 56 | plot(y, type = 'b') 57 | acf(y) 58 | pacf(y) 59 | 60 | 61 | -------------------------------------------------------------------------------- /Ch03/periodogram.R: -------------------------------------------------------------------------------- 1 | x <- 1:1024 2 | y <- sin(x * pi / 5) 3 | f <- fft(y) 4 | plot(f * f) 5 | 6 | ## stats package 7 | require(stats) 8 | spectrum(y) 9 | 10 | ## TSA package 11 | require(TSA) 12 | periodogram(y) 13 | 14 | ## roll your own with stats fft package 15 | 16 | 17 | ## http://www.di.fc.ul.pt/~jpn/r/fourier/fourier.html 18 | plot.frequency.spectrum <- function(X.k, xlimits=c(0,length(X.k))) { 19 | plot.data <- cbind(0:(length(X.k)-1), Mod(X.k)) 20 | 21 | plot.data[2:length(X.k),2] <- 2*plot.data[2:length(X.k),2] 22 | 23 | plot(plot.data, t="h", lwd=2, main="", 24 | xlab="Frequency (Hz)", ylab="Strength", 25 | xlim=xlimits, ylim=c(0,max(Mod(plot.data[,2])))) 26 | } 27 | 28 | plot.frequency.spectrum(y) 29 | 30 | acq.freq <- 100 # data acquisition (sample) frequency (Hz) 31 | time <- 6 # measuring time interval (seconds) 32 | ts <- seq(0,time-1/acq.freq,1/acq.freq) # vector of sampling time-points (s) 33 | f.0 <- 1/time 34 | 35 | dc.component. <- 1 36 | component.freqs <- c(3,7,10) # frequency of signal components (Hz) 37 | component.delay <- c(0,0,0) # delay of signal components (radians) 38 | component.strength <- c(1.5,.5,.75) # strength of signal components 39 | 40 | f <- function(t,w) { 41 | dc.component + 42 | sum( component.strength * sin(component.freqs*w*t + component.delay)) 43 | } 44 | 45 | plot.fourier(f,f.0,ts=ts) 46 | 47 | w <- 2*pi*f.0 48 | trajectory <- sapply(ts, function(t) f(t,w)) 49 | head(trajectory,n=30) 50 | 51 | X.k <- fft(trajectory) # find all harmonics with fft() 52 | plot.frequency.spectrum(X.k, xlimits=c(0,20)) 53 | -------------------------------------------------------------------------------- /Ch04/Ising.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "%matplotlib inline\n", 10 | "import matplotlib.pyplot as plt\n", 11 | "plt.rcParams['figure.figsize'] = [10, 5]\n", 12 | "\n", 13 | "import pdb\n", 14 | "import numpy as np" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "## inspired by https://rajeshrinet.github.io/blog/2014/ising-model/\n", 24 | "\n", 25 | "### CONFIGURATION\n", 26 | "N = 5 # width of lattice\n", 27 | "M = 5 # height of lattice\n", 28 | "temperature = 0.5\n", 29 | "BETA = 1 / temperature" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": null, 35 | "metadata": {}, 36 | "outputs": [], 37 | "source": [ 38 | "# initialize system\n", 39 | "def initRandState(N, M):\n", 40 | " block = np.random.choice([-1, 1], size = (N, M))\n", 41 | " return block" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": null, 47 | "metadata": {}, 48 | "outputs": [], 49 | "source": [ 50 | "def costForCenterState(state, i, j, n, m):\n", 51 | " centerS = state[i, j]\n", 52 | " neighbors = [((i + 1) % n, j), ((i - 1) % n, j),\n", 53 | " (i, (j + 1) % m), (i, (j - 1) % m)]\n", 54 | " ## notice the % n because we impose periodic boundary conditions\n", 55 | " ## ignore this if it doesn't make sense - it's merely a physical constraint on the system\n", 56 | "\n", 57 | " interactionE = [state[x, y] * centerS for (x, y) in neighbors]\n", 58 | " return np.sum(interactionE)\n", 59 | "\n", 60 | "\n", 61 | "def magnetizationForState(state):\n", 62 | " return np.sum(state)" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": null, 68 | "metadata": {}, 69 | "outputs": [], 70 | "source": [ 71 | "# mcmc steps\n", 72 | "def mcmcAdjust(state):\n", 73 | " n = state.shape[0]\n", 74 | " m = state.shape[1]\n", 75 | " x, y = np.random.randint(0, n), np.random.randint(0, m)\n", 76 | " centerS = state[x, y]\n", 77 | " cost = costForCenterState(state, x, y, n, m)\n", 78 | " if cost < 0:\n", 79 | " centerS *= -1\n", 80 | " elif np.random.random() < np.exp(-cost * BETA):\n", 81 | " centerS *= -1\n", 82 | " state[x, y] = centerS\n", 83 | " return state\n", 84 | " \n", 85 | "def runState(state, n_steps, snapsteps = None):\n", 86 | " if snapsteps is None:\n", 87 | " snapsteps = np.linspace(0, n_steps, num = round(n_steps / (M * N * 100)), dtype = np.int32)\n", 88 | " saved_states = []\n", 89 | " sp = 0\n", 90 | " magnet_hist = []\n", 91 | " for i in range(n_steps):\n", 92 | " state = mcmcAdjust(state)\n", 93 | " magnet_hist.append(magnetizationForState(state))\n", 94 | " if sp < len(snapsteps) and i == snapsteps[sp]:\n", 95 | " saved_states.append(np.copy(state))\n", 96 | " sp += 1\n", 97 | " return state, saved_states, magnet_hist\n", 98 | "\n" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": null, 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "### RUN A SIMULATION\n", 108 | "init_state = initRandState(N, M)\n", 109 | "plt.imshow(init_state)\n" 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": null, 115 | "metadata": {}, 116 | "outputs": [], 117 | "source": [ 118 | "final_state, states, magnet_hist = runState(init_state, 1000)" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": null, 124 | "metadata": {}, 125 | "outputs": [], 126 | "source": [ 127 | "plt.imshow(final_state)" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": null, 133 | "metadata": {}, 134 | "outputs": [], 135 | "source": [ 136 | "plt.plot(magnet_hist)" 137 | ] 138 | }, 139 | { 140 | "cell_type": "markdown", 141 | "metadata": {}, 142 | "source": [ 143 | "## Exercise: Modify the simulation code above to visualize magnetization over time for 100 test runs" 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": null, 149 | "metadata": {}, 150 | "outputs": [], 151 | "source": [ 152 | "results = []\n", 153 | "for i in range(100):\n", 154 | " init_state = initRandState(N, M)\n", 155 | " final_state, states, magnet_hist = runState(init_state, 1000)\n", 156 | " results.append(magnet_hist)" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": null, 162 | "metadata": {}, 163 | "outputs": [], 164 | "source": [ 165 | "for mh in results:\n", 166 | " plt.plot(mh,'r', alpha=0.2)" 167 | ] 168 | }, 169 | { 170 | "cell_type": "markdown", 171 | "metadata": {}, 172 | "source": [ 173 | "## Exercise: generate a curve of absolute value of magnetization at step 100 for temperature for temperatures = 0.1, 0.5, 1, 2, 5, 20, 50, 100, 500" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": null, 179 | "metadata": {}, 180 | "outputs": [], 181 | "source": [ 182 | "results = []\n", 183 | "temps = [0.1, 0.5, 1, 2, 5, 20, 50, 100, 500]\n", 184 | "\n", 185 | "# mcmc steps\n", 186 | "def mcmcAdjust(state, beta):\n", 187 | " n = state.shape[0]\n", 188 | " m = state.shape[1]\n", 189 | " x, y = np.random.randint(0, n), np.random.randint(0, m)\n", 190 | " centerS = state[x, y]\n", 191 | " cost = costForCenterState(state, x, y, n, m)\n", 192 | " if cost < 0:\n", 193 | " centerS *= -1\n", 194 | " elif np.random.random() < np.exp(-cost * beta):\n", 195 | " centerS *= -1\n", 196 | " state[x, y] = centerS\n", 197 | " return state\n", 198 | " \n", 199 | "def runState(state, beta, n_steps, snapsteps = None):\n", 200 | " if snapsteps is None:\n", 201 | " snapsteps = np.linspace(0, n_steps, num = round(n_steps / (M * N * 100)), dtype = np.int32)\n", 202 | " saved_states = []\n", 203 | " sp = 0\n", 204 | " magnet_hist = []\n", 205 | " for i in range(n_steps):\n", 206 | " state = mcmcAdjust(state, beta)\n", 207 | " magnet_hist.append(magnetizationForState(state))\n", 208 | " if sp < len(snapsteps) and i == snapsteps[sp]:\n", 209 | " saved_states.append(np.copy(state))\n", 210 | " sp += 1\n", 211 | " return state, saved_states, magnet_hist\n", 212 | "\n", 213 | "\n", 214 | "res = []\n", 215 | "for temp in temps:\n", 216 | " temp_res = []\n", 217 | " for _ in range(20):\n", 218 | " init_state = initRandState(N, M)\n", 219 | " final_state, states, magnet_hist = runState(init_state, 1/temp, 100)\n", 220 | " temp_res.append(abs(magnet_hist[-1]))\n", 221 | " res.append(np.mean(temp_res))" 222 | ] 223 | }, 224 | { 225 | "cell_type": "code", 226 | "execution_count": null, 227 | "metadata": {}, 228 | "outputs": [], 229 | "source": [ 230 | "temps" 231 | ] 232 | }, 233 | { 234 | "cell_type": "code", 235 | "execution_count": null, 236 | "metadata": {}, 237 | "outputs": [], 238 | "source": [ 239 | "plt.plot(temps, res)" 240 | ] 241 | }, 242 | { 243 | "cell_type": "markdown", 244 | "metadata": {}, 245 | "source": [ 246 | "## Exercise: what might an agent-based model look like when applied to this problem?" 247 | ] 248 | }, 249 | { 250 | "cell_type": "code", 251 | "execution_count": null, 252 | "metadata": {}, 253 | "outputs": [], 254 | "source": [] 255 | } 256 | ], 257 | "metadata": { 258 | "kernelspec": { 259 | "display_name": "Python 3", 260 | "language": "python", 261 | "name": "python3" 262 | }, 263 | "language_info": { 264 | "codemirror_mode": { 265 | "name": "ipython", 266 | "version": 3 267 | }, 268 | "file_extension": ".py", 269 | "mimetype": "text/x-python", 270 | "name": "python", 271 | "nbconvert_exporter": "python", 272 | "pygments_lexer": "ipython3", 273 | "version": "3.6.8" 274 | } 275 | }, 276 | "nbformat": 4, 277 | "nbformat_minor": 2 278 | } 279 | -------------------------------------------------------------------------------- /Ch07/BSTS.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "%matplotlib inline\n", 10 | "import matplotlib\n", 11 | "matplotlib.rcParams['figure.figsize'] = [8, 3]\n", 12 | "import matplotlib.pyplot as plt\n", 13 | "\n", 14 | "import pandas as pd\n", 15 | "import numpy as np\n", 16 | "import statsmodels.api as sm\n", 17 | "import statsmodels\n", 18 | "\n", 19 | "import scipy\n", 20 | "from scipy.stats import pearsonr\n", 21 | "\n", 22 | "from pandas.plotting import register_matplotlib_converters\n", 23 | "register_matplotlib_converters()" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [ 32 | "print(matplotlib.__version__)\n", 33 | "print(pd.__version__)\n", 34 | "print(np.__version__)\n", 35 | "print(statsmodels.__version__)\n", 36 | "print(scipy.__version__)\n" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": {}, 42 | "source": [ 43 | "## Obtain and visualize data" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "## data obtained from https://datahub.io/core/global-temp#data\n", 53 | "df = pd.read_csv(\"global_temps.csv\")\n", 54 | "df.head()" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [ 63 | "df.Mean[:100].plot()" 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "metadata": {}, 69 | "source": [ 70 | "## Exercise: what is wrong with the data and plot above? How can we fix this?" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": null, 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | " df = df.pivot(index='Date', columns='Source', values='Mean')" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "df.head()" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "df.GCAG.plot()" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [ 106 | "type(df.index)" 107 | ] 108 | }, 109 | { 110 | "cell_type": "markdown", 111 | "metadata": {}, 112 | "source": [ 113 | "## Exercise: how can we make the index more time aware?" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": null, 119 | "metadata": {}, 120 | "outputs": [], 121 | "source": [ 122 | "df.index = pd.to_datetime(df.index)" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": null, 128 | "metadata": {}, 129 | "outputs": [], 130 | "source": [ 131 | "type(df.index)" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": null, 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "df.GCAG.plot()" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": null, 146 | "metadata": {}, 147 | "outputs": [], 148 | "source": [ 149 | "df['1880']" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": null, 155 | "metadata": {}, 156 | "outputs": [], 157 | "source": [ 158 | "plt.plot(df['1880':'1950'][['GCAG', 'GISTEMP']])" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": null, 164 | "metadata": {}, 165 | "outputs": [], 166 | "source": [ 167 | "plt.plot(df['1950':][['GISTEMP']])" 168 | ] 169 | }, 170 | { 171 | "cell_type": "markdown", 172 | "metadata": {}, 173 | "source": [ 174 | "## Exercise: How strongly do these measurements correlate contemporaneously? What about with a time lag?" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": null, 180 | "metadata": {}, 181 | "outputs": [], 182 | "source": [ 183 | "plt.scatter(df['1880':'1900'][['GCAG']], df['1880':'1900'][['GISTEMP']])" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": null, 189 | "metadata": {}, 190 | "outputs": [], 191 | "source": [ 192 | "plt.scatter(df['1880':'1899'][['GCAG']], df['1881':'1900'][['GISTEMP']])" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": null, 198 | "metadata": {}, 199 | "outputs": [], 200 | "source": [ 201 | "pearsonr(df['1880':'1899'].GCAG, df['1881':'1900'].GISTEMP)" 202 | ] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "execution_count": null, 207 | "metadata": {}, 208 | "outputs": [], 209 | "source": [ 210 | "df['1880':'1899'][['GCAG']].head()" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": null, 216 | "metadata": {}, 217 | "outputs": [], 218 | "source": [ 219 | "df['1881':'1900'][['GISTEMP']].head()" 220 | ] 221 | }, 222 | { 223 | "cell_type": "code", 224 | "execution_count": null, 225 | "metadata": {}, 226 | "outputs": [], 227 | "source": [ 228 | "min(df.index)" 229 | ] 230 | }, 231 | { 232 | "cell_type": "code", 233 | "execution_count": null, 234 | "metadata": {}, 235 | "outputs": [], 236 | "source": [ 237 | "max(df.index)" 238 | ] 239 | }, 240 | { 241 | "cell_type": "markdown", 242 | "metadata": {}, 243 | "source": [ 244 | "## Unobserved component model" 245 | ] 246 | }, 247 | { 248 | "cell_type": "code", 249 | "execution_count": null, 250 | "metadata": {}, 251 | "outputs": [], 252 | "source": [ 253 | "train = df['1960':]" 254 | ] 255 | }, 256 | { 257 | "cell_type": "markdown", 258 | "metadata": {}, 259 | "source": [ 260 | "### model parameters" 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": null, 266 | "metadata": {}, 267 | "outputs": [], 268 | "source": [ 269 | "# smooth trend model without seasonal or cyclical components\n", 270 | "model = {\n", 271 | " 'level': 'smooth trend', 'cycle': False, 'seasonal': None, \n", 272 | "}\n" 273 | ] 274 | }, 275 | { 276 | "cell_type": "markdown", 277 | "metadata": {}, 278 | "source": [ 279 | "### fitting a model" 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": null, 285 | "metadata": { 286 | "scrolled": true 287 | }, 288 | "outputs": [], 289 | "source": [ 290 | "# https://www.statsmodels.org/dev/generated/statsmodels.tsa.statespace.structural.UnobservedComponents.html\n", 291 | "gcag_mod = sm.tsa.UnobservedComponents(train['GCAG'], **model)\n", 292 | "gcag_res = gcag_mod.fit()" 293 | ] 294 | }, 295 | { 296 | "cell_type": "code", 297 | "execution_count": null, 298 | "metadata": {}, 299 | "outputs": [], 300 | "source": [ 301 | "fig = gcag_res.plot_components(legend_loc='lower right', figsize=(15, 9));" 302 | ] 303 | }, 304 | { 305 | "cell_type": "markdown", 306 | "metadata": {}, 307 | "source": [ 308 | "## Plotting predictions" 309 | ] 310 | }, 311 | { 312 | "cell_type": "code", 313 | "execution_count": null, 314 | "metadata": {}, 315 | "outputs": [], 316 | "source": [ 317 | "# Perform rolling prediction and multistep forecast\n", 318 | "num_steps = 20\n", 319 | "predict_res = gcag_res.get_prediction(dynamic=train['GCAG'].shape[0] - num_steps)\n", 320 | "\n", 321 | "predict = predict_res.predicted_mean\n", 322 | "ci = predict_res.conf_int()" 323 | ] 324 | }, 325 | { 326 | "cell_type": "code", 327 | "execution_count": null, 328 | "metadata": {}, 329 | "outputs": [], 330 | "source": [ 331 | "plt.plot(predict)" 332 | ] 333 | }, 334 | { 335 | "cell_type": "code", 336 | "execution_count": null, 337 | "metadata": {}, 338 | "outputs": [], 339 | "source": [ 340 | "plt.scatter(train['GCAG'], predict)" 341 | ] 342 | }, 343 | { 344 | "cell_type": "code", 345 | "execution_count": null, 346 | "metadata": {}, 347 | "outputs": [], 348 | "source": [ 349 | "fig, ax = plt.subplots()\n", 350 | "# Plot the results\n", 351 | "ax.plot(train['GCAG'], 'k.', label='Observations');\n", 352 | "ax.plot(train.index[:-num_steps], predict[:-num_steps], label='One-step-ahead Prediction');\n", 353 | "\n", 354 | "ax.plot(train.index[-num_steps:], predict[-num_steps:], 'r', label='Multistep Prediction');\n", 355 | "ax.plot(train.index[-num_steps:], ci.iloc[-num_steps:], 'k--');\n", 356 | "\n", 357 | "# Cleanup the image\n", 358 | "legend = ax.legend(loc='upper left');" 359 | ] 360 | }, 361 | { 362 | "cell_type": "code", 363 | "execution_count": null, 364 | "metadata": {}, 365 | "outputs": [], 366 | "source": [ 367 | "fig, ax = plt.subplots()\n", 368 | "# Plot the results\n", 369 | "ax.plot(train.index[-40:], train['GCAG'][-40:], 'k.', label='Observations');\n", 370 | "ax.plot(train.index[-40:-num_steps], predict[-40:-num_steps], label='One-step-ahead Prediction');\n", 371 | "\n", 372 | "ax.plot(train.index[-num_steps:], predict[-num_steps:], 'r', label='Multistep Prediction');\n", 373 | "ax.plot(train.index[-num_steps:], ci.iloc[-num_steps:], 'k--');\n", 374 | "\n", 375 | "# Cleanup the image\n", 376 | "legend = ax.legend(loc='upper left');" 377 | ] 378 | }, 379 | { 380 | "cell_type": "markdown", 381 | "metadata": {}, 382 | "source": [ 383 | "## Exercise: consider adding a seasonal term for 12 periods for the model fit above. Does this improve the fit of the model?" 384 | ] 385 | }, 386 | { 387 | "cell_type": "code", 388 | "execution_count": null, 389 | "metadata": {}, 390 | "outputs": [], 391 | "source": [ 392 | "seasonal_model = {\n", 393 | " 'level': 'local linear trend',\n", 394 | " 'seasonal': 12\n", 395 | "}\n", 396 | "mod = sm.tsa.UnobservedComponents(train['GCAG'], **seasonal_model)\n", 397 | "res = mod.fit(method='powell', disp=False)" 398 | ] 399 | }, 400 | { 401 | "cell_type": "code", 402 | "execution_count": null, 403 | "metadata": {}, 404 | "outputs": [], 405 | "source": [ 406 | "fig = res.plot_components(legend_loc='lower right', figsize=(15, 9));" 407 | ] 408 | }, 409 | { 410 | "cell_type": "markdown", 411 | "metadata": {}, 412 | "source": [ 413 | "## How does this compare to the original model?" 414 | ] 415 | }, 416 | { 417 | "cell_type": "code", 418 | "execution_count": null, 419 | "metadata": {}, 420 | "outputs": [], 421 | "source": [ 422 | "pearsonr(gcag_res.predict(), train['GCAG'])" 423 | ] 424 | }, 425 | { 426 | "cell_type": "code", 427 | "execution_count": null, 428 | "metadata": {}, 429 | "outputs": [], 430 | "source": [ 431 | "np.mean(np.abs(gcag_res.predict() - train['GCAG']))" 432 | ] 433 | }, 434 | { 435 | "cell_type": "code", 436 | "execution_count": null, 437 | "metadata": {}, 438 | "outputs": [], 439 | "source": [ 440 | "np.mean(np.abs(res.predict() - train['GCAG']))" 441 | ] 442 | }, 443 | { 444 | "cell_type": "markdown", 445 | "metadata": {}, 446 | "source": [ 447 | "## Explore the seasonality more" 448 | ] 449 | }, 450 | { 451 | "cell_type": "code", 452 | "execution_count": null, 453 | "metadata": {}, 454 | "outputs": [], 455 | "source": [ 456 | "seasonal_model = {\n", 457 | " 'level': 'local level',\n", 458 | " 'seasonal': 12\n", 459 | "}\n", 460 | "llmod = sm.tsa.UnobservedComponents(train['GCAG'], **seasonal_model)\n", 461 | "ll_level_res = llmod.fit(method='powell', disp=False)" 462 | ] 463 | }, 464 | { 465 | "cell_type": "code", 466 | "execution_count": null, 467 | "metadata": {}, 468 | "outputs": [], 469 | "source": [ 470 | "fig = ll_level_res.plot_components(legend_loc='lower right', figsize=(15, 9));" 471 | ] 472 | }, 473 | { 474 | "cell_type": "code", 475 | "execution_count": null, 476 | "metadata": {}, 477 | "outputs": [], 478 | "source": [ 479 | "np.mean(np.abs(ll_level_res.predict() - train['GCAG']))" 480 | ] 481 | }, 482 | { 483 | "cell_type": "code", 484 | "execution_count": null, 485 | "metadata": {}, 486 | "outputs": [], 487 | "source": [ 488 | "train[:48].GCAG.plot()" 489 | ] 490 | }, 491 | { 492 | "cell_type": "code", 493 | "execution_count": null, 494 | "metadata": {}, 495 | "outputs": [], 496 | "source": [] 497 | }, 498 | { 499 | "cell_type": "markdown", 500 | "metadata": {}, 501 | "source": [ 502 | "## Exercise: a common null model for time series is to predict the value at time t-1 for the value at time t. How does such a model compare to the models we fit here?" 503 | ] 504 | }, 505 | { 506 | "cell_type": "markdown", 507 | "metadata": {}, 508 | "source": [ 509 | "### Consider correlation" 510 | ] 511 | }, 512 | { 513 | "cell_type": "code", 514 | "execution_count": null, 515 | "metadata": {}, 516 | "outputs": [], 517 | "source": [ 518 | "pearsonr(ll_level_res.predict(), train['GCAG'])" 519 | ] 520 | }, 521 | { 522 | "cell_type": "code", 523 | "execution_count": null, 524 | "metadata": {}, 525 | "outputs": [], 526 | "source": [ 527 | "pearsonr(train['GCAG'].iloc[:-1, ], train['GCAG'].iloc[1:, ])" 528 | ] 529 | }, 530 | { 531 | "cell_type": "markdown", 532 | "metadata": {}, 533 | "source": [ 534 | "### What about mean absolute error?" 535 | ] 536 | }, 537 | { 538 | "cell_type": "code", 539 | "execution_count": null, 540 | "metadata": {}, 541 | "outputs": [], 542 | "source": [ 543 | "np.mean(np.abs(ll_level_res.predict() - train['GCAG']))" 544 | ] 545 | }, 546 | { 547 | "cell_type": "code", 548 | "execution_count": null, 549 | "metadata": {}, 550 | "outputs": [], 551 | "source": [ 552 | "np.mean(np.abs(train['GCAG'].iloc[:-1, ].values, train['GCAG'].iloc[1:, ].values))" 553 | ] 554 | }, 555 | { 556 | "cell_type": "code", 557 | "execution_count": null, 558 | "metadata": {}, 559 | "outputs": [], 560 | "source": [] 561 | } 562 | ], 563 | "metadata": { 564 | "kernelspec": { 565 | "display_name": "Python 3", 566 | "language": "python", 567 | "name": "python3" 568 | }, 569 | "language_info": { 570 | "codemirror_mode": { 571 | "name": "ipython", 572 | "version": 3 573 | }, 574 | "file_extension": ".py", 575 | "mimetype": "text/x-python", 576 | "name": "python", 577 | "nbconvert_exporter": "python", 578 | "pygments_lexer": "ipython3", 579 | "version": "3.6.8" 580 | } 581 | }, 582 | "nbformat": 4, 583 | "nbformat_minor": 2 584 | } 585 | -------------------------------------------------------------------------------- /Ch07/Nile.csv: -------------------------------------------------------------------------------- 1 | "","year","val" 2 | "1",1871,1120 3 | "2",1872,1160 4 | "3",1873,963 5 | "4",1874,1210 6 | "5",1875,1160 7 | "6",1876,1160 8 | "7",1877,813 9 | "8",1878,1230 10 | "9",1879,1370 11 | "10",1880,1140 12 | "11",1881,995 13 | "12",1882,935 14 | "13",1883,1110 15 | "14",1884,994 16 | "15",1885,1020 17 | "16",1886,960 18 | "17",1887,1180 19 | "18",1888,799 20 | "19",1889,958 21 | "20",1890,1140 22 | "21",1891,1100 23 | "22",1892,1210 24 | "23",1893,1150 25 | "24",1894,1250 26 | "25",1895,1260 27 | "26",1896,1220 28 | "27",1897,1030 29 | "28",1898,1100 30 | "29",1899,774 31 | "30",1900,840 32 | "31",1901,874 33 | "32",1902,694 34 | "33",1903,940 35 | "34",1904,833 36 | "35",1905,701 37 | "36",1906,916 38 | "37",1907,692 39 | "38",1908,1020 40 | "39",1909,1050 41 | "40",1910,969 42 | "41",1911,831 43 | "42",1912,726 44 | "43",1913,456 45 | "44",1914,824 46 | "45",1915,702 47 | "46",1916,1120 48 | "47",1917,1100 49 | "48",1918,832 50 | "49",1919,764 51 | "50",1920,821 52 | "51",1921,768 53 | "52",1922,845 54 | "53",1923,864 55 | "54",1924,862 56 | "55",1925,698 57 | "56",1926,845 58 | "57",1927,744 59 | "58",1928,796 60 | "59",1929,1040 61 | "60",1930,759 62 | "61",1931,781 63 | "62",1932,865 64 | "63",1933,845 65 | "64",1934,944 66 | "65",1935,984 67 | "66",1936,897 68 | "67",1937,822 69 | "68",1938,1010 70 | "69",1939,771 71 | "70",1940,676 72 | "71",1941,649 73 | "72",1942,846 74 | "73",1943,812 75 | "74",1944,742 76 | "75",1945,801 77 | "76",1946,1040 78 | "77",1947,860 79 | "78",1948,874 80 | "79",1949,848 81 | "80",1950,890 82 | "81",1951,744 83 | "82",1952,749 84 | "83",1953,838 85 | "84",1954,1050 86 | "85",1955,918 87 | "86",1956,986 88 | "87",1957,797 89 | "88",1958,923 90 | "89",1959,975 91 | "90",1960,815 92 | "91",1961,1020 93 | "92",1962,906 94 | "93",1963,901 95 | "94",1964,1170 96 | "95",1965,912 97 | "96",1966,746 98 | "97",1967,919 99 | "98",1968,718 100 | "99",1969,714 101 | "100",1970,740 102 | -------------------------------------------------------------------------------- /Ch07/kalman_filter.r: -------------------------------------------------------------------------------- 1 | 2 | ## thank you Alex Hagaman! 3 | 4 | ## rocket will take 100 time steps 5 | ts.length <- 100 6 | 7 | ## the acceleration will drive the motion 8 | a <- rep(0.5, ts.length) 9 | 10 | ## position and velocity start at 0 11 | x <- rep(0, ts.length) 12 | v <- rep(0, ts.length) 13 | for (ts in 2:ts.length) { 14 | x[ts] <- v[ts - 1] * 2 + x[ts - 1] + 1/2 * a[ts - 1] ^ 2 15 | x[ts] <- x[ts] + rnorm(1, sd = 20) ## stochastic component 16 | v[ts] <- v[ts - 1] + 2 * a[ts - 1] 17 | } 18 | 19 | par(mfrow = c(3, 1)) 20 | plot(x, main = "Position", type = 'l') 21 | plot(v, main = "Velocity", type = 'l') 22 | plot(a, main = "Acceleration", type = 'l') 23 | 24 | ## simulate noisy sensor measurement 25 | z <- x + rnorm(ts.length, sd = 300) 26 | par(mfrow = c(1, 1)) 27 | plot(x, ylim = range(c(x, z))) 28 | lines(z) 29 | 30 | ## apply a Kalman filter 31 | kalman.motion <- function(z, Q, R, A, H) { 32 | dimState = dim(Q)[1] 33 | 34 | xhatminus <- array(rep(0, ts.length * dimState), 35 | c(ts.length, dimState)) 36 | xhat <- array(rep(0, ts.length * dimState), 37 | c(ts.length, dimState)) 38 | 39 | Pminus <- array(rep(0, ts.length * dimState * dimState), 40 | c(ts.length, dimState, dimState)) 41 | P <- array(rep(0, ts.length * dimState * dimState), 42 | c(ts.length, dimState, dimState)) 43 | 44 | K <- array(rep(0, ts.length * dimState), 45 | c(ts.length, dimState)) # Kalman gain 46 | 47 | # initial guesses = starting at 0 for all metrics 48 | xhat[1, ] <- rep(0, dimState) 49 | P[1, , ] <- diag(dimState) 50 | 51 | for (k in 2:ts.length) { 52 | # time update 53 | xhatminus[k, ] <- A %*% matrix(xhat[k-1, ]) 54 | Pminus[k, , ] <- A %*% P[k-1, , ] %*% t(A) + Q 55 | 56 | K[k, ] <- Pminus[k, , ] %*% H %*% 57 | solve( t(H) %*% Pminus[k, , ] %*% H + R ) 58 | xhat[k, ] <- xhatminus[k, ] + K[k, ] %*% 59 | (z[k] - t(H) %*% xhatminus[k, ]) 60 | P[k, , ] <- (diag(dimState) - K[k, ] %*% t(H)) %*% Pminus[k, , ] 61 | } 62 | 63 | ## we return both the forecast and the smoothed value 64 | return(list(xhat = xhat, xhatminus = xhatminus)) 65 | } 66 | 67 | ## noise parameters 68 | R <- 10^2 ## measurement variance - this value should be set 69 | ## according to known physical limits of measuring tool 70 | ## we set it consistent with the noise we added to x 71 | ## to produce x in the data generation above 72 | Q <- 10 ## process variance - usually regarded as hyperparameter 73 | ## to be used to maximize performance 74 | 75 | ## dynamical parameters 76 | A <- matrix(1) ## x_t = A * x_t - 1 (how prior x affects later x) 77 | H <- matrix(1) ## y_t = H * x_t (translating state to measurement) 78 | 79 | ## run the data through the Kalman filtering method 80 | xhat <- kalman.motion(z, diag(1) * Q, R, A, H)[[1]] 81 | xhatminus <- kalman.motion(z, diag(1) * Q, R, A, H)[[2]] 82 | 83 | ## visualization 84 | plot(z, ylim = range(c(x, z)), type = 'l', 85 | col = "black", lwd = 2) 86 | lines(x, col = "red", lwd = 2, lty = 2) 87 | lines(xhat, col = "orange", lwd = 1, lty = 3) 88 | lines(xhatminus, col = "blue", lwd = 1, lty = 4) 89 | legend("topleft", 90 | legend = c("Measured", "Actual", "Filtered", "Forecast"), 91 | col = c("black", "red", "orange", "blue"), 92 | lty = 1:4) 93 | -------------------------------------------------------------------------------- /Ch07/kalman_filter_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PracticalTimeSeriesAnalysis/BookRepo/cb20c277addd0e02423b7f965d4114cc806c287a/Ch07/kalman_filter_plot.png -------------------------------------------------------------------------------- /Ch09/Classification.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import matplotlib.pyplot as plt\n", 10 | "plt.rcParams['figure.figsize'] = [10, 10]" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "metadata": {}, 17 | "outputs": [], 18 | "source": [ 19 | "import cesium\n", 20 | "import xgboost as xgb\n", 21 | "import numpy as np\n", 22 | "import matplotlib.pyplot as plt\n", 23 | "import pandas as pd\n", 24 | "import time\n", 25 | "\n", 26 | "from cesium import datasets\n", 27 | "from cesium import featurize as ft\n", 28 | "\n", 29 | "import scipy\n", 30 | "from scipy.stats import pearsonr, spearmanr\n", 31 | "from scipy.stats import skew\n", 32 | "\n", 33 | "import sklearn\n", 34 | "from sklearn.ensemble import RandomForestClassifier\n", 35 | "from sklearn.metrics import accuracy_score\n", 36 | "from sklearn.model_selection import train_test_split" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "print(cesium.__version__)\n", 46 | "print(xgb.__version__)\n", 47 | "print(scipy.__version__)\n", 48 | "print(sklearn.__version__)" 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "metadata": {}, 54 | "source": [ 55 | "## Load data and generate some features of interest" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": null, 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "eeg = datasets.fetch_andrzejak()" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": null, 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "type(eeg)" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": null, 79 | "metadata": {}, 80 | "outputs": [], 81 | "source": [ 82 | "eeg.keys()" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "### Visually inspect" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": null, 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "plt.subplot(3, 1, 1)\n", 99 | "plt.plot(eeg[\"measurements\"][0])\n", 100 | "plt.legend(eeg['classes'][0])\n", 101 | "plt.subplot(3, 1, 2)\n", 102 | "plt.plot(eeg[\"measurements\"][300])\n", 103 | "plt.legend(eeg['classes'][300])\n", 104 | "plt.subplot(3, 1, 3)\n", 105 | "plt.plot(eeg[\"measurements\"][450])\n", 106 | "plt.legend(eeg['classes'][450])" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": null, 112 | "metadata": {}, 113 | "outputs": [], 114 | "source": [ 115 | "type(eeg[\"measurements\"][0])" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": null, 121 | "metadata": {}, 122 | "outputs": [], 123 | "source": [ 124 | "type(eeg)" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": null, 130 | "metadata": {}, 131 | "outputs": [], 132 | "source": [ 133 | "eeg.keys()" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": null, 139 | "metadata": {}, 140 | "outputs": [], 141 | "source": [ 142 | "type(eeg['measurements'])" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": null, 148 | "metadata": {}, 149 | "outputs": [], 150 | "source": [ 151 | "len(eeg['measurements'])" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": null, 157 | "metadata": {}, 158 | "outputs": [], 159 | "source": [ 160 | "eeg['measurements'][0].shape" 161 | ] 162 | }, 163 | { 164 | "cell_type": "markdown", 165 | "metadata": {}, 166 | "source": [ 167 | "## Generate the features" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": null, 173 | "metadata": {}, 174 | "outputs": [], 175 | "source": [ 176 | "# from cesium import featurize as ft\n", 177 | "# features_to_use = [\"amplitude\",\n", 178 | "# \"percent_beyond_1_std\",\n", 179 | "# \"percent_close_to_median\",\n", 180 | "# \"skew\",\n", 181 | "# \"max_slope\"]\n", 182 | "# fset_cesium = ft.featurize_time_series(times=eeg[\"times\"],\n", 183 | "# values=eeg[\"measurements\"],\n", 184 | "# errors=None,\n", 185 | "# features_to_use=features_to_use,\n", 186 | "# scheduler = None)" 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": null, 192 | "metadata": {}, 193 | "outputs": [], 194 | "source": [ 195 | "fset_cesium = pd.read_csv(\"data/full_eeg_data_features.csv\", header = [0, 1])" 196 | ] 197 | }, 198 | { 199 | "cell_type": "code", 200 | "execution_count": null, 201 | "metadata": { 202 | "scrolled": true 203 | }, 204 | "outputs": [], 205 | "source": [ 206 | "fset_cesium.head()" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": null, 212 | "metadata": {}, 213 | "outputs": [], 214 | "source": [ 215 | "# fset_cesium.to_csv(\"full_eeg_data_features.csv\")" 216 | ] 217 | }, 218 | { 219 | "cell_type": "code", 220 | "execution_count": null, 221 | "metadata": {}, 222 | "outputs": [], 223 | "source": [ 224 | "fset_cesium.shape" 225 | ] 226 | }, 227 | { 228 | "cell_type": "markdown", 229 | "metadata": {}, 230 | "source": [ 231 | "## Exercise: validate/calculate these features by hand\n", 232 | "#### look up feature definitions here: http://cesium-ml.org/docs/feature_table.html\n", 233 | "confirm the values by hand coding these features for the first EEG measurement\n", 234 | "(that is eeg[\"measurements\"][0])" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": null, 240 | "metadata": {}, 241 | "outputs": [], 242 | "source": [ 243 | "ex = eeg[\"measurements\"][0]" 244 | ] 245 | }, 246 | { 247 | "cell_type": "code", 248 | "execution_count": null, 249 | "metadata": {}, 250 | "outputs": [], 251 | "source": [ 252 | "ex_mean = np.mean(ex)\n", 253 | "ex_std = np.std(ex)" 254 | ] 255 | }, 256 | { 257 | "cell_type": "code", 258 | "execution_count": null, 259 | "metadata": {}, 260 | "outputs": [], 261 | "source": [ 262 | "# amplitude\n", 263 | "(np.max(ex) - np.min(ex)) / 2" 264 | ] 265 | }, 266 | { 267 | "cell_type": "code", 268 | "execution_count": null, 269 | "metadata": {}, 270 | "outputs": [], 271 | "source": [ 272 | " \n", 273 | "siz = len(ex)\n", 274 | "ll = ex_mean - ex_std\n", 275 | "ul = ex_mean + ex_std\n", 276 | "\n", 277 | "quals = [i for i in range(siz) if ex[i] < ll or ex[i] > ul]\n", 278 | "len(quals)/len(ex)" 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "execution_count": null, 284 | "metadata": {}, 285 | "outputs": [], 286 | "source": [ 287 | "# percent_close_to_median\n", 288 | "# Percentage of values within window_frac*(max(x)-min(x)) of median.\n", 289 | "# find the source code here:\n", 290 | "# https://github.com/cesium-ml/cesium/blob/master/cesium/features/common_functions.py\n", 291 | "# window frac = 0.1\n", 292 | "window = 0.1 * (np.max(ex) - np.min(ex))\n", 293 | "np.where(np.abs(ex_mean - ex) < window)[0].shape[0] / ex.shape[0]" 294 | ] 295 | }, 296 | { 297 | "cell_type": "code", 298 | "execution_count": null, 299 | "metadata": {}, 300 | "outputs": [], 301 | "source": [ 302 | "## skew\n", 303 | "print(skew(ex))\n", 304 | "plt.hist(ex)" 305 | ] 306 | }, 307 | { 308 | "cell_type": "code", 309 | "execution_count": null, 310 | "metadata": {}, 311 | "outputs": [], 312 | "source": [ 313 | "## max slope\n", 314 | "## again check definition : https://github.com/cesium-ml/cesium/blob/master/cesium/features/common_functions.py\n", 315 | "times = eeg[\"times\"][0]\n", 316 | "np.max(np.abs(np.diff(ex)/np.diff(times)))" 317 | ] 318 | }, 319 | { 320 | "cell_type": "code", 321 | "execution_count": null, 322 | "metadata": {}, 323 | "outputs": [], 324 | "source": [ 325 | "plt.hist(fset_cesium.iloc[:, 1])" 326 | ] 327 | }, 328 | { 329 | "cell_type": "code", 330 | "execution_count": null, 331 | "metadata": {}, 332 | "outputs": [], 333 | "source": [ 334 | "fset_cesium['classes'] = eeg['classes']" 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": null, 340 | "metadata": {}, 341 | "outputs": [], 342 | "source": [ 343 | "fset_cesium.columns = fset_cesium.columns.droplevel(-1)" 344 | ] 345 | }, 346 | { 347 | "cell_type": "code", 348 | "execution_count": null, 349 | "metadata": {}, 350 | "outputs": [], 351 | "source": [ 352 | "fset_cesium.groupby('classes')['amplitude'].hist()" 353 | ] 354 | }, 355 | { 356 | "cell_type": "code", 357 | "execution_count": null, 358 | "metadata": {}, 359 | "outputs": [], 360 | "source": [ 361 | "fset_cesium['amplitude'].hist(by=fset_cesium['classes'])" 362 | ] 363 | }, 364 | { 365 | "cell_type": "code", 366 | "execution_count": null, 367 | "metadata": {}, 368 | "outputs": [], 369 | "source": [ 370 | "fset_cesium['max_slope'].hist(by=fset_cesium['classes'])" 371 | ] 372 | }, 373 | { 374 | "cell_type": "markdown", 375 | "metadata": {}, 376 | "source": [ 377 | "## Prepare data for training" 378 | ] 379 | }, 380 | { 381 | "cell_type": "code", 382 | "execution_count": null, 383 | "metadata": {}, 384 | "outputs": [], 385 | "source": [ 386 | "X_train, X_test, y_train, y_test = train_test_split(\n", 387 | " fset_cesium.iloc[:, 1:6].values, eeg[\"classes\"], random_state=21)" 388 | ] 389 | }, 390 | { 391 | "cell_type": "markdown", 392 | "metadata": {}, 393 | "source": [ 394 | "## Try a random forest with these features" 395 | ] 396 | }, 397 | { 398 | "cell_type": "code", 399 | "execution_count": null, 400 | "metadata": {}, 401 | "outputs": [], 402 | "source": [ 403 | "clf = RandomForestClassifier(n_estimators=10, max_depth=3,\n", 404 | " random_state=21)" 405 | ] 406 | }, 407 | { 408 | "cell_type": "code", 409 | "execution_count": null, 410 | "metadata": {}, 411 | "outputs": [], 412 | "source": [ 413 | "clf.fit(X_train, y_train)" 414 | ] 415 | }, 416 | { 417 | "cell_type": "code", 418 | "execution_count": null, 419 | "metadata": {}, 420 | "outputs": [], 421 | "source": [ 422 | "clf.score(X_train, y_train)" 423 | ] 424 | }, 425 | { 426 | "cell_type": "code", 427 | "execution_count": null, 428 | "metadata": {}, 429 | "outputs": [], 430 | "source": [ 431 | "clf.score(X_test, y_test)" 432 | ] 433 | }, 434 | { 435 | "cell_type": "code", 436 | "execution_count": null, 437 | "metadata": {}, 438 | "outputs": [], 439 | "source": [ 440 | "np.unique(y_test, return_counts=True)" 441 | ] 442 | }, 443 | { 444 | "cell_type": "code", 445 | "execution_count": null, 446 | "metadata": {}, 447 | "outputs": [], 448 | "source": [ 449 | "y_test" 450 | ] 451 | }, 452 | { 453 | "cell_type": "code", 454 | "execution_count": null, 455 | "metadata": {}, 456 | "outputs": [], 457 | "source": [ 458 | "y_test.shape" 459 | ] 460 | }, 461 | { 462 | "cell_type": "code", 463 | "execution_count": null, 464 | "metadata": {}, 465 | "outputs": [], 466 | "source": [ 467 | "y_train.shape" 468 | ] 469 | }, 470 | { 471 | "cell_type": "markdown", 472 | "metadata": {}, 473 | "source": [ 474 | "## Try XGBoost with these features" 475 | ] 476 | }, 477 | { 478 | "cell_type": "code", 479 | "execution_count": null, 480 | "metadata": {}, 481 | "outputs": [], 482 | "source": [ 483 | "model = xgb.XGBClassifier(n_estimators=10, max_depth=3,\n", 484 | " random_state=21)\n", 485 | "model.fit(X_train, y_train)" 486 | ] 487 | }, 488 | { 489 | "cell_type": "code", 490 | "execution_count": null, 491 | "metadata": {}, 492 | "outputs": [], 493 | "source": [ 494 | "model.score(X_test, y_test)" 495 | ] 496 | }, 497 | { 498 | "cell_type": "code", 499 | "execution_count": null, 500 | "metadata": {}, 501 | "outputs": [], 502 | "source": [ 503 | "model.score(X_train, y_train)" 504 | ] 505 | }, 506 | { 507 | "cell_type": "code", 508 | "execution_count": null, 509 | "metadata": {}, 510 | "outputs": [], 511 | "source": [ 512 | "xgb.plot_importance(model)" 513 | ] 514 | }, 515 | { 516 | "cell_type": "markdown", 517 | "metadata": {}, 518 | "source": [ 519 | "## Time Series Forecasting with Decision Trees" 520 | ] 521 | }, 522 | { 523 | "cell_type": "code", 524 | "execution_count": null, 525 | "metadata": {}, 526 | "outputs": [], 527 | "source": [ 528 | "ap = pd.read_csv(\"data/AirPassengers.csv\", parse_dates=[0])" 529 | ] 530 | }, 531 | { 532 | "cell_type": "code", 533 | "execution_count": null, 534 | "metadata": {}, 535 | "outputs": [], 536 | "source": [ 537 | "ap.head()" 538 | ] 539 | }, 540 | { 541 | "cell_type": "code", 542 | "execution_count": null, 543 | "metadata": {}, 544 | "outputs": [], 545 | "source": [ 546 | "ap.set_index('Month', inplace=True)" 547 | ] 548 | }, 549 | { 550 | "cell_type": "code", 551 | "execution_count": null, 552 | "metadata": {}, 553 | "outputs": [], 554 | "source": [ 555 | "ap.head()" 556 | ] 557 | }, 558 | { 559 | "cell_type": "code", 560 | "execution_count": null, 561 | "metadata": {}, 562 | "outputs": [], 563 | "source": [ 564 | "plt.plot(ap)" 565 | ] 566 | }, 567 | { 568 | "cell_type": "code", 569 | "execution_count": null, 570 | "metadata": {}, 571 | "outputs": [], 572 | "source": [ 573 | "plt.plot(np.diff(np.log(ap.values[:, 0])))" 574 | ] 575 | }, 576 | { 577 | "cell_type": "code", 578 | "execution_count": null, 579 | "metadata": {}, 580 | "outputs": [], 581 | "source": [ 582 | "ts = np.diff(np.log(ap.values[:, 0]))" 583 | ] 584 | }, 585 | { 586 | "cell_type": "markdown", 587 | "metadata": {}, 588 | "source": [ 589 | "## Exercise: now that we have 1 time series, how can we convert it to many samples?" 590 | ] 591 | }, 592 | { 593 | "cell_type": "code", 594 | "execution_count": null, 595 | "metadata": {}, 596 | "outputs": [], 597 | "source": [ 598 | "NSTEPS = 12" 599 | ] 600 | }, 601 | { 602 | "cell_type": "code", 603 | "execution_count": null, 604 | "metadata": {}, 605 | "outputs": [], 606 | "source": [ 607 | "ts.shape" 608 | ] 609 | }, 610 | { 611 | "cell_type": "code", 612 | "execution_count": null, 613 | "metadata": {}, 614 | "outputs": [], 615 | "source": [ 616 | "vals = np.hstack([np.expand_dims(np.array(ts, dtype = np.float32), axis = 1) for _ in range(NSTEPS )])" 617 | ] 618 | }, 619 | { 620 | "cell_type": "code", 621 | "execution_count": null, 622 | "metadata": {}, 623 | "outputs": [], 624 | "source": [ 625 | "ts[0:NSTEPS]" 626 | ] 627 | }, 628 | { 629 | "cell_type": "code", 630 | "execution_count": null, 631 | "metadata": {}, 632 | "outputs": [], 633 | "source": [ 634 | "vals.shape" 635 | ] 636 | }, 637 | { 638 | "cell_type": "code", 639 | "execution_count": null, 640 | "metadata": {}, 641 | "outputs": [], 642 | "source": [ 643 | "nrow = vals.shape[0]\n", 644 | "for lag in range(1, vals.shape[1]):\n", 645 | " vals[:(nrow - lag),lag] = vals[lag:,lag]\n", 646 | " vals[(nrow - lag):, lag] = np.nan" 647 | ] 648 | }, 649 | { 650 | "cell_type": "code", 651 | "execution_count": null, 652 | "metadata": {}, 653 | "outputs": [], 654 | "source": [ 655 | "vals" 656 | ] 657 | }, 658 | { 659 | "cell_type": "code", 660 | "execution_count": null, 661 | "metadata": {}, 662 | "outputs": [], 663 | "source": [ 664 | "vals = vals[:(vals.shape[0] - NSTEPS + 1), :]" 665 | ] 666 | }, 667 | { 668 | "cell_type": "code", 669 | "execution_count": null, 670 | "metadata": {}, 671 | "outputs": [], 672 | "source": [ 673 | "vals.shape" 674 | ] 675 | }, 676 | { 677 | "cell_type": "code", 678 | "execution_count": null, 679 | "metadata": {}, 680 | "outputs": [], 681 | "source": [ 682 | "vals[-1]" 683 | ] 684 | }, 685 | { 686 | "cell_type": "code", 687 | "execution_count": null, 688 | "metadata": {}, 689 | "outputs": [], 690 | "source": [ 691 | "ts[-NSTEPS:]" 692 | ] 693 | }, 694 | { 695 | "cell_type": "code", 696 | "execution_count": null, 697 | "metadata": {}, 698 | "outputs": [], 699 | "source": [ 700 | "vals.shape" 701 | ] 702 | }, 703 | { 704 | "cell_type": "markdown", 705 | "metadata": {}, 706 | "source": [ 707 | "## Exercise: now that we have the time series broken down into a set of samples, how to featurize?" 708 | ] 709 | }, 710 | { 711 | "cell_type": "code", 712 | "execution_count": null, 713 | "metadata": {}, 714 | "outputs": [], 715 | "source": [ 716 | "measures = [vals[i][0:(NSTEPS - 1)] for i in range(vals.shape[0])]" 717 | ] 718 | }, 719 | { 720 | "cell_type": "code", 721 | "execution_count": null, 722 | "metadata": {}, 723 | "outputs": [], 724 | "source": [ 725 | "times = [[j for j in range(NSTEPS - 1)] for i in range(vals.shape[0])]" 726 | ] 727 | }, 728 | { 729 | "cell_type": "code", 730 | "execution_count": null, 731 | "metadata": {}, 732 | "outputs": [], 733 | "source": [ 734 | "measures[0]" 735 | ] 736 | }, 737 | { 738 | "cell_type": "code", 739 | "execution_count": null, 740 | "metadata": {}, 741 | "outputs": [], 742 | "source": [ 743 | "len(measures[0])" 744 | ] 745 | }, 746 | { 747 | "cell_type": "code", 748 | "execution_count": null, 749 | "metadata": {}, 750 | "outputs": [], 751 | "source": [ 752 | "features_to_use = [\n", 753 | " \"amplitude\",\n", 754 | " \"percent_beyond_1_std\",\n", 755 | " \"skew\",\n", 756 | " \"max_slope\",\n", 757 | " \"percent_amplitude\"]\n", 758 | "fset_ap = ft.featurize_time_series(times=times,\n", 759 | " values=measures,\n", 760 | " errors=None,\n", 761 | " features_to_use=features_to_use,\n", 762 | " scheduler = None)" 763 | ] 764 | }, 765 | { 766 | "cell_type": "code", 767 | "execution_count": null, 768 | "metadata": {}, 769 | "outputs": [], 770 | "source": [ 771 | "fset_ap.columns = fset_ap.columns.droplevel(-1)" 772 | ] 773 | }, 774 | { 775 | "cell_type": "code", 776 | "execution_count": null, 777 | "metadata": {}, 778 | "outputs": [], 779 | "source": [ 780 | "fset_ap.head()" 781 | ] 782 | }, 783 | { 784 | "cell_type": "code", 785 | "execution_count": null, 786 | "metadata": {}, 787 | "outputs": [], 788 | "source": [ 789 | "plt.hist(fset_ap.amplitude)" 790 | ] 791 | }, 792 | { 793 | "cell_type": "code", 794 | "execution_count": null, 795 | "metadata": {}, 796 | "outputs": [], 797 | "source": [ 798 | "plt.hist(fset_ap.percent_amplitude)" 799 | ] 800 | }, 801 | { 802 | "cell_type": "code", 803 | "execution_count": null, 804 | "metadata": {}, 805 | "outputs": [], 806 | "source": [ 807 | "plt.hist(fset_ap['skew'])" 808 | ] 809 | }, 810 | { 811 | "cell_type": "markdown", 812 | "metadata": {}, 813 | "source": [ 814 | "## Exercise: can you fit an XGBRegressor to this problem? Let's use the first 100 'time series' as the training data" 815 | ] 816 | }, 817 | { 818 | "cell_type": "code", 819 | "execution_count": null, 820 | "metadata": {}, 821 | "outputs": [], 822 | "source": [ 823 | "outcomes = vals[:, -1]" 824 | ] 825 | }, 826 | { 827 | "cell_type": "code", 828 | "execution_count": null, 829 | "metadata": {}, 830 | "outputs": [], 831 | "source": [ 832 | "X_train, y_train = fset_ap.iloc[:100, :], outcomes[:100]\n", 833 | "X_test, y_test = fset_ap.iloc[100:, :], outcomes[100:]" 834 | ] 835 | }, 836 | { 837 | "cell_type": "code", 838 | "execution_count": null, 839 | "metadata": {}, 840 | "outputs": [], 841 | "source": [ 842 | "X_train.shape" 843 | ] 844 | }, 845 | { 846 | "cell_type": "code", 847 | "execution_count": null, 848 | "metadata": {}, 849 | "outputs": [], 850 | "source": [ 851 | "model = xgb.XGBRegressor(n_estimators=20, max_depth=2,\n", 852 | " random_state=21)" 853 | ] 854 | }, 855 | { 856 | "cell_type": "code", 857 | "execution_count": null, 858 | "metadata": {}, 859 | "outputs": [], 860 | "source": [ 861 | "eval_set = [(X_test, y_test)]\n", 862 | "model.fit(X_train, y_train, eval_metric=\"rmse\", eval_set=eval_set, verbose=True)" 863 | ] 864 | }, 865 | { 866 | "cell_type": "markdown", 867 | "metadata": {}, 868 | "source": [ 869 | "### RMSE can be hard to digest .... How does the model perform?" 870 | ] 871 | }, 872 | { 873 | "cell_type": "code", 874 | "execution_count": null, 875 | "metadata": {}, 876 | "outputs": [], 877 | "source": [ 878 | "plt.scatter(model.predict(X_test), y_test)" 879 | ] 880 | }, 881 | { 882 | "cell_type": "code", 883 | "execution_count": null, 884 | "metadata": {}, 885 | "outputs": [], 886 | "source": [ 887 | "plt.scatter(model.predict(X_train), y_train)" 888 | ] 889 | }, 890 | { 891 | "cell_type": "code", 892 | "execution_count": null, 893 | "metadata": {}, 894 | "outputs": [], 895 | "source": [ 896 | "pearsonr(model.predict(X_train), y_train)" 897 | ] 898 | }, 899 | { 900 | "cell_type": "code", 901 | "execution_count": null, 902 | "metadata": {}, 903 | "outputs": [], 904 | "source": [ 905 | "pearsonr(model.predict(X_test), y_test)" 906 | ] 907 | }, 908 | { 909 | "cell_type": "code", 910 | "execution_count": null, 911 | "metadata": {}, 912 | "outputs": [], 913 | "source": [ 914 | "xgb.plot_importance(model)" 915 | ] 916 | }, 917 | { 918 | "cell_type": "markdown", 919 | "metadata": {}, 920 | "source": [ 921 | "### What went wrong? Let's revisit the feature set" 922 | ] 923 | }, 924 | { 925 | "cell_type": "code", 926 | "execution_count": null, 927 | "metadata": {}, 928 | "outputs": [], 929 | "source": [ 930 | "fset_ap.head()" 931 | ] 932 | }, 933 | { 934 | "cell_type": "code", 935 | "execution_count": null, 936 | "metadata": {}, 937 | "outputs": [], 938 | "source": [ 939 | "plt.plot(vals[0])\n", 940 | "plt.plot(vals[1])\n", 941 | "plt.plot(vals[2])" 942 | ] 943 | }, 944 | { 945 | "cell_type": "markdown", 946 | "metadata": {}, 947 | "source": [ 948 | "## We need to find a way to generate features that encode positional information" 949 | ] 950 | }, 951 | { 952 | "cell_type": "markdown", 953 | "metadata": {}, 954 | "source": [ 955 | "### now we will generate our own features" 956 | ] 957 | }, 958 | { 959 | "cell_type": "code", 960 | "execution_count": null, 961 | "metadata": {}, 962 | "outputs": [], 963 | "source": [ 964 | "vals.shape" 965 | ] 966 | }, 967 | { 968 | "cell_type": "code", 969 | "execution_count": null, 970 | "metadata": {}, 971 | "outputs": [], 972 | "source": [ 973 | "feats = np.zeros( (vals.shape[0], 6), dtype = np.float32)\n", 974 | "for i in range(vals.shape[0]):\n", 975 | " feats[i, 0] = np.where(vals[i] == np.max(vals[i]))[0][0]\n", 976 | " feats[i, 1] = np.where(vals[i] == np.min(vals[i]))[0][0]\n", 977 | " feats[i, 2] = feats[i, 0] - feats[i, 1]\n", 978 | " feats[i, 3] = np.max(vals[i][-3:])\n", 979 | " feats[i, 4] = vals[i][-1] - vals[i][-2]\n", 980 | " feats[i, 5] = vals[i][-1] - vals[i][-3]" 981 | ] 982 | }, 983 | { 984 | "cell_type": "code", 985 | "execution_count": null, 986 | "metadata": {}, 987 | "outputs": [], 988 | "source": [ 989 | "feats[0:3]" 990 | ] 991 | }, 992 | { 993 | "cell_type": "markdown", 994 | "metadata": {}, 995 | "source": [ 996 | "### How do these look compared to the first set of features?" 997 | ] 998 | }, 999 | { 1000 | "cell_type": "code", 1001 | "execution_count": null, 1002 | "metadata": {}, 1003 | "outputs": [], 1004 | "source": [ 1005 | "pd.DataFrame(feats[0:3])" 1006 | ] 1007 | }, 1008 | { 1009 | "cell_type": "code", 1010 | "execution_count": null, 1011 | "metadata": {}, 1012 | "outputs": [], 1013 | "source": [ 1014 | "X_train, y_train = feats[:100, :], outcomes[:100]\n", 1015 | "X_test, y_test = feats[100:, :], outcomes[100:]" 1016 | ] 1017 | }, 1018 | { 1019 | "cell_type": "code", 1020 | "execution_count": null, 1021 | "metadata": {}, 1022 | "outputs": [], 1023 | "source": [ 1024 | "model = xgb.XGBRegressor(n_estimators=20, max_depth=2,\n", 1025 | " random_state=21)\n", 1026 | "eval_set = [(X_test, y_test)]\n", 1027 | "model.fit(X_train, y_train, eval_metric=\"rmse\", eval_set=eval_set, verbose=True)" 1028 | ] 1029 | }, 1030 | { 1031 | "cell_type": "code", 1032 | "execution_count": null, 1033 | "metadata": {}, 1034 | "outputs": [], 1035 | "source": [ 1036 | "plt.scatter(model.predict(X_test), y_test)" 1037 | ] 1038 | }, 1039 | { 1040 | "cell_type": "code", 1041 | "execution_count": null, 1042 | "metadata": {}, 1043 | "outputs": [], 1044 | "source": [ 1045 | "print(pearsonr(model.predict(X_test), y_test))\n", 1046 | "print(spearmanr(model.predict(X_test), y_test))" 1047 | ] 1048 | }, 1049 | { 1050 | "cell_type": "code", 1051 | "execution_count": null, 1052 | "metadata": {}, 1053 | "outputs": [], 1054 | "source": [ 1055 | "plt.scatter(model.predict(X_train), y_train)" 1056 | ] 1057 | }, 1058 | { 1059 | "cell_type": "code", 1060 | "execution_count": null, 1061 | "metadata": {}, 1062 | "outputs": [], 1063 | "source": [ 1064 | "print(pearsonr(model.predict(X_train), y_train))\n", 1065 | "print(spearmanr(model.predict(X_train), y_train))" 1066 | ] 1067 | }, 1068 | { 1069 | "cell_type": "code", 1070 | "execution_count": null, 1071 | "metadata": {}, 1072 | "outputs": [], 1073 | "source": [] 1074 | } 1075 | ], 1076 | "metadata": { 1077 | "kernelspec": { 1078 | "display_name": "Python 3", 1079 | "language": "python", 1080 | "name": "python3" 1081 | }, 1082 | "language_info": { 1083 | "codemirror_mode": { 1084 | "name": "ipython", 1085 | "version": 3 1086 | }, 1087 | "file_extension": ".py", 1088 | "mimetype": "text/x-python", 1089 | "name": "python", 1090 | "nbconvert_exporter": "python", 1091 | "pygments_lexer": "ipython3", 1092 | "version": "3.6.8" 1093 | } 1094 | }, 1095 | "nbformat": 4, 1096 | "nbformat_minor": 2 1097 | } 1098 | -------------------------------------------------------------------------------- /Ch09/full_eeg_data_features.csv: -------------------------------------------------------------------------------- 1 | feature,amplitude,percent_beyond_1_std,percent_close_to_median,skew,max_slope 2 | channel,0,0,0,0,0 3 | 0,143.5,0.3273126678057115,0.5050036612155235,0.03280499636078603,11107.796610166752 4 | 1,211.5,0.29021235050036615,0.6404686355870148,-0.09271499211959769,20653.559322035173 5 | 2,165.0,0.3026604832804491,0.5159873077861851,-0.004099908422673498,13537.627118640728 6 | 3,171.5,0.300951916036124,0.5411276543812545,0.06367751324413805,17008.813559317838 7 | 4,170.0,0.305101293629485,0.5662680009763241,0.14275337323253015,13016.949152543175 8 | 5,151.5,0.3087625091530388,0.5247742250427142,0.0025011817593482595,10934.237288132896 9 | 6,162.0,0.30851842811813524,0.5318525750549182,0.003178683279414835,12843.389830505306 10 | 7,126.5,0.32462777642177204,0.565779838906517,-0.023596653944598325,8851.525423732088 11 | 8,105.0,0.32413961435196487,0.491091042226019,-0.002426031720372573,7463.050847455786 12 | 9,156.0,0.3021723212106419,0.546741518184037,0.20265028735172702,10934.237288132896 13 | 10,149.5,0.3107151574322675,0.5643153526970954,-0.12018981338006451,8677.966101692775 14 | 11,138.5,0.29558213326824506,0.528435440566268,-0.0914853389237861,13537.627118640728 15 | 12,109.0,0.3129118867463998,0.49694898706370516,0.005112452544532662,9025.084745760485 16 | 13,155.5,0.3019282401757383,0.5599218940688309,0.0551950414951377,8330.847457627633 17 | 14,102.0,0.30851842811813524,0.5555284354405663,-0.2813200124947303,7636.610169491996 18 | 15,184.0,0.300951916036124,0.5696851354649743,-0.19576677245427937,19265.084745757962 19 | 16,105.0,0.3019282401757383,0.5064681474249451,0.05057527697813485,9892.881355929763 20 | 17,195.5,0.2950939711984379,0.5660239199414205,0.07750325162235075,13364.067796615114 21 | 18,104.0,0.3087625091530388,0.5093971198437881,-0.047926331764203724,9372.203389831086 22 | 19,91.0,0.3170612643397608,0.5184281181352209,-0.12282530171016943,6942.3728813585 23 | 20,112.0,0.31388821088601415,0.564559433731999,0.19772523755260535,14231.86440677615 24 | 21,104.5,0.30339272638515985,0.5301440078105931,0.009343864947020985,19785.762711859526 25 | 22,190.5,0.2948498901635343,0.586526726873322,-0.18445856807259337,12843.389830508771 26 | 23,132.0,0.3143763729558213,0.5482060043934587,0.05441434741046727,16488.135593226438 27 | 24,159.5,0.3109592384671711,0.4635098852819136,-0.0901991558303276,13016.949152543175 28 | 25,253.0,0.30851842811813524,0.6429094459360508,-0.11708687788202442,23430.508474577717 29 | 26,130.5,0.3094947522577496,0.5135464974371491,0.008883432689729694,14752.54237288113 30 | 27,117.5,0.31193556260678545,0.5098852819135953,-0.07316764334419591,9198.644067794341 31 | 28,185.0,0.3019282401757383,0.6258237734927996,0.06531278308475195,15273.220338983992 32 | 29,218.0,0.3043690505247742,0.6058091286307054,0.0960385552926802,22562.711864404693 33 | 30,110.5,0.2963143763729558,0.5787161337564072,0.07790220910380466,6421.694915254633 34 | 31,91.0,0.300951916036124,0.517207712960703,-0.02665173820853917,8157.288135593723 35 | 32,172.0,0.30803026604832806,0.5713937027092995,0.1281218207705191,21521.35593220472 36 | 33,151.5,0.2982670246521845,0.5508908957773981,0.19479536922250987,15446.779661013139 37 | 34,192.5,0.3070539419087137,0.5259946302172321,0.1944848378138337,9545.762711867937 38 | 35,185.5,0.3126678057114962,0.5679765682206492,-0.17373333914649158,10934.237288139639 39 | 36,152.0,0.3212106419331218,0.49890163534293386,-0.12839434685318554,11802.033898305812 40 | 37,77.5,0.30656577983890654,0.49304369050524777,0.07675374403247699,6942.3728813585 41 | 38,210.0,0.29753478154747376,0.5589455699292165,-0.14888363338453664,23604.067796604348 42 | 39,131.0,0.31974615572370024,0.560410056138638,0.02578137341318412,14405.423728813337 43 | 40,158.5,0.3231632902123505,0.5120820112277276,0.01279664987429101,15793.898305080851 44 | 41,85.5,0.32487185745667563,0.5252623871125214,0.08600235300137501,8157.288135591209 45 | 42,119.0,0.3109592384671711,0.5552843544056627,0.1262179320381637,9198.644067796646 46 | 43,162.5,0.31242372467659263,0.5430803026604832,-0.13702931248190797,12669.830508475357 47 | 44,161.0,0.31047107639736393,0.5814010251403466,0.06799017285955924,10239.999999999842 48 | 45,156.0,0.2909445936050769,0.6072736148401269,0.050949044827945746,10934.237288135424 49 | 46,157.0,0.3112033195020747,0.535513790578472,-0.09044246584647368,10413.55932203133 50 | 47,170.0,0.2987551867219917,0.5794483768611179,-0.27929314157056667,26728.135593213745 51 | 48,116.5,0.3094947522577496,0.5362460336831828,0.08411350317599015,17355.93220338555 52 | 49,184.5,0.31364412985111056,0.5294117647058824,-0.05568467198929736,12669.830508471452 53 | 50,152.0,0.3004637539663168,0.5796924578960215,0.042278635183069,16314.576271187447 54 | 51,158.0,0.3234073712472541,0.5933609958506224,0.10240705352065199,18050.169491526536 55 | 52,110.0,0.3170612643397608,0.5140346595069563,-0.14830482464416553,7636.610169491996 56 | 53,188.5,0.31974615572370024,0.5240419819380034,-0.07282103060058218,23083.38983050278 57 | 54,166.5,0.3087625091530388,0.5450329509397119,-0.06717106475638081,17182.372881351694 58 | 55,165.5,0.3112033195020747,0.5018306077617769,-0.029556580074265235,14926.101694916175 59 | 56,176.5,0.305101293629485,0.5472296802538443,0.0738900009776722,14752.542372886814 60 | 57,141.5,0.3278008298755187,0.5233097388332927,-0.10793657338677244,12843.389830509266 61 | 58,138.5,0.3109592384671711,0.5596778130339273,-0.02674970530364729,8504.406779658919 62 | 59,112.5,0.31193556260678545,0.511837930192824,0.10408196642892907,9025.084745760485 63 | 60,75.5,0.3053453746643886,0.5169636319257994,-0.07186513816829429,6074.576271186816 64 | 61,229.0,0.2662924090798145,0.6675616304613131,-0.0890551466197215,12149.152542369884 65 | 62,114.0,0.31974615572370024,0.4947522577495729,0.1592440030908038,11975.59322033603 66 | 63,160.0,0.3024164022455455,0.5528435440566268,-0.013304940593891493,12322.71186440374 67 | 64,151.0,0.30119599707102757,0.597754454478887,0.01659679798518148,11802.033898302174 68 | 65,83.0,0.30998291432755676,0.5023187698315841,-0.10337812351339892,10934.237288132896 69 | 66,160.5,0.303880888454967,0.5357578716133756,-0.1318463160088896,10934.237288136268 70 | 67,157.0,0.303880888454967,0.5699292164998779,-0.18634578591698683,11975.59322033972 71 | 68,158.0,0.33707590920185504,0.4652184525262387,0.04290607378154484,11281.355932203405 72 | 69,160.0,0.30851842811813524,0.5028069319013913,-0.09693873069555951,11975.593220343413 73 | 70,182.0,0.3214547229680254,0.5079326336343666,0.039788323027199174,14578.983050843863 74 | 71,153.5,0.3214547229680254,0.4979253112033195,0.046354025407720184,13016.949152539162 75 | 72,93.0,0.31730534537466437,0.5374664388577007,-0.040916364244612244,8157.288135591209 76 | 73,135.5,0.30851842811813524,0.5111056870881132,-0.016050162578528503,9198.644067794341 77 | 74,154.0,0.3270685867708079,0.5115938491579204,0.08890377434229327,12149.152542369884 78 | 75,142.5,0.2909445936050769,0.604832804491091,-0.35237033147660357,8677.966101692775 79 | 76,197.5,0.300951916036124,0.5804247010007323,-0.13680448311099466,23256.949152543806 80 | 77,161.0,0.30632169880400295,0.6150842079570418,-0.004943108577697385,14058.30508474663 81 | 78,126.5,0.31242372467659263,0.5013424456919697,0.16050139028577426,10066.440677969826 82 | 79,70.5,0.3309738833292653,0.4693678301195997,-0.059687350093763906,6595.2542372905755 83 | 80,136.5,0.3077861850134245,0.528435440566268,-0.1583681960920406,10934.237288135424 84 | 81,195.0,0.3070539419087137,0.5945814010251403,0.023071260958911443,13190.508474577084 85 | 82,109.5,0.3143763729558213,0.5301440078105931,-0.15972747233765447,16314.576271187447 86 | 83,124.5,0.3170612643397608,0.47644618013180373,-0.029448968728342195,12322.71186440754 87 | 84,163.0,0.3053453746643886,0.5457651940444227,0.16893582887187686,17355.9322033909 88 | 85,138.5,0.30827434708323165,0.5137905784720527,-0.09936851581024819,11281.355932207563 89 | 86,139.0,0.3004637539663168,0.5291676836709788,-0.000687710262205894,12322.71186440754 90 | 87,146.5,0.300951916036124,0.5218452526238712,-0.0626146354656131,13884.74576270844 91 | 88,131.5,0.30803026604832806,0.535513790578472,0.027440998554386104,13537.627118644903 92 | 89,193.0,0.3112033195020747,0.5777398096167927,-0.025072066701994803,13711.186440678812 93 | 90,144.5,0.31632902123505,0.4874298267024652,-0.04670618265914194,10760.67796610236 94 | 91,187.5,0.3019282401757383,0.6416890407615329,-0.1821313415554348,11975.59322033603 95 | 92,159.5,0.3053453746643886,0.5399072492067366,0.053677976173119986,13711.18644068304 96 | 93,196.0,0.29362948498901636,0.5731022699536246,-0.10397035981041869,18223.728813554826 97 | 94,179.5,0.30998291432755676,0.5872589699780327,-0.12221028049891067,14405.423728810007 98 | 95,217.5,0.28118135220893337,0.7144251891628021,-0.10178878324101877,16488.135593216273 99 | 96,149.5,0.29607029533805224,0.553331706126434,-0.18852667303438408,14405.423728810007 100 | 97,154.5,0.3043690505247742,0.5323407371247254,-0.15735832993597343,9719.322033895907 101 | 98,162.5,0.3212106419331218,0.5257505491823286,0.006840407593553521,12843.389830507287 102 | 99,151.0,0.2928972418843056,0.5572370026848914,0.21180852814184375,11454.915254237994 103 | 100,204.0,0.3077861850134245,0.5123260922626311,0.04828606506025026,42001.35593220598 104 | 101,327.5,0.33390285574810835,0.4373932145472297,0.07224288114800591,59010.169491529065 105 | 102,180.0,0.3109592384671711,0.5596778130339273,0.1682968468974367,17355.932203396253 106 | 103,156.5,0.3112033195020747,0.47913107151574325,-0.10845178127318873,12669.830508475357 107 | 104,224.0,0.3187698315840859,0.5711496216743959,0.12434966474966874,19438.644067791814 108 | 105,279.5,0.3475713937027093,0.3861361972174762,-0.05712565370260951,48075.9322033928 109 | 106,354.5,0.338296314376373,0.48254820600439347,0.012238628136870931,42348.474576273795 110 | 107,216.5,0.3090065901879424,0.48865023187698314,0.04931542198837519,27075.254237289806 111 | 108,203.5,0.31608494020014644,0.48669758359775445,-0.0879855311968265,35406.10169491744 112 | 109,185.0,0.30632169880400295,0.553331706126434,0.03882361642848398,20653.559322028803 113 | 110,186.0,0.31632902123505,0.561630461313156,0.13859366396532377,14405.423728814447 114 | 111,209.0,0.2985111056870881,0.5928728337808152,0.022401690648624677,25166.101694909048 115 | 112,242.5,0.300951916036124,0.5401513302416402,0.2854546158209247,22736.27118644208 116 | 113,241.0,0.30314864535025626,0.5565047595801806,0.02696295145001843,24645.42372881508 117 | 114,204.0,0.31413229192091774,0.503539175006102,-0.09725939589433434,20653.559322035173 118 | 115,200.0,0.3165731022699536,0.5508908957773981,0.1276460159119754,16661.694915255266 119 | 116,168.5,0.3004637539663168,0.5767634854771784,0.03855256906546692,13364.067796610994 120 | 117,158.5,0.31754942640956796,0.5208689284842568,-0.06718824772476736,13711.186440678812 121 | 118,192.5,0.29216499877959484,0.5457651940444227,0.06079859581591024,18223.728813560447 122 | 119,218.0,0.3004637539663168,0.575787161337564,-0.01568708445509518,17355.932203396253 123 | 120,311.0,0.2970466194776666,0.6136197217476203,0.21743915805848246,21694.91525423194 124 | 121,167.5,0.3182816695142787,0.4940200146448621,0.18143201095874387,14578.983050843863 125 | 122,231.0,0.31779350744447155,0.5560165975103735,0.09916516670096082,25860.338983060414 126 | 123,269.5,0.3087625091530388,0.556260678545277,-0.01252411785912201,25686.779661016553 127 | 124,278.5,0.3046131315596778,0.6111789113985844,-0.17174297701557836,24992.542372875192 128 | 125,181.5,0.31022699536246034,0.5545521113009519,0.045062552400909194,15446.779661016712 129 | 126,182.0,0.30998291432755676,0.5709055406394923,-0.04035148941558203,15967.457627118398 130 | 127,182.0,0.3126678057114962,0.5391750061020258,-0.04044455438291556,14752.542372877717 131 | 128,256.0,0.3053453746643886,0.5111056870881132,-0.07509688495530134,24298.305084739768 132 | 129,191.0,0.30851842811813524,0.5989748596534049,-0.09054962439377601,15446.779661013139 133 | 130,197.5,0.30485721259458143,0.5867708079082256,-0.018787971357900154,18570.84745763399 134 | 131,248.5,0.30119599707102757,0.6175250183060776,0.08614798686312188,21000.677966096515 135 | 132,248.0,0.300951916036124,0.5679765682206492,-0.09009249720930514,22736.27118644208 136 | 133,311.0,0.29045643153526973,0.5845740785940933,0.21935099109565503,27422.372881357624 137 | 134,196.0,0.31022699536246034,0.5072003905296558,0.11485110258228737,19785.762711859526 138 | 135,272.0,0.30851842811813524,0.5416158164510617,-0.031308879448844744,25513.220338976756 139 | 136,267.5,0.29045643153526973,0.5399072492067366,0.06679465574251647,20653.559322033878 140 | 137,208.0,0.313400048816207,0.5120820112277276,0.05594880436024939,21521.355932198083 141 | 138,190.0,0.32267512814254334,0.5115938491579204,0.06214659500427859,18744.406779656394 142 | 139,202.5,0.30998291432755676,0.5399072492067366,0.10071730975436947,16661.694915260403 143 | 140,220.0,0.29948742982670246,0.556260678545277,0.17448533607403013,36447.45762710965 144 | 141,173.5,0.3019282401757383,0.5506468147424946,0.021618092519283486,16835.254237289173 145 | 142,181.0,0.31632902123505,0.5364901147180864,0.00045227528100456215,22215.593220340354 146 | 143,135.0,0.31584085916524285,0.5267268733219429,0.07072670926352863,8504.406779658919 147 | 144,237.5,0.2963143763729558,0.5806687820356359,0.28763292171475,19785.762711859526 148 | 145,141.5,0.3114474005369783,0.5711496216743959,-0.025362285320020123,16661.69491525013 149 | 146,266.0,0.30656577983890654,0.5840859165242861,0.06570609753059917,19612.203389831717 150 | 147,240.0,0.2828899194532585,0.6009275079326336,0.11664289802041249,19091.525423724106 151 | 148,135.0,0.29387356602391995,0.5501586526726874,0.13110445207889823,13884.74576270844 152 | 149,110.0,0.3214547229680254,0.532584818159629,0.05164158419802332,8677.966101692775 153 | 150,142.5,0.30119599707102757,0.5496704906028802,-0.05887513733117941,19612.203389830585 154 | 151,175.5,0.3007078350012204,0.5938491579204296,-0.10071347787584078,27769.491525423302 155 | 152,217.5,0.29729070051257017,0.5879912130827435,0.3102097780255876,18397.288135588682 156 | 153,141.5,0.31364412985111056,0.5364901147180864,0.18210961815851337,19612.203389830207 157 | 154,240.0,0.27971686599951184,0.5584574078594093,0.20280597386301966,27248.813559323713 158 | 155,262.0,0.30607761776909936,0.5357578716133756,0.34344967838090124,26033.898305084596 159 | 156,148.5,0.28313400048816206,0.5682206492555528,0.10285547381492562,13190.508474577084 160 | 157,155.5,0.30339272638515985,0.6038564803514767,-0.0696340025807991,11628.474576271006 161 | 158,119.0,0.3087625091530388,0.5582133268245058,-0.24531599482318206,11107.7966101736 162 | 159,342.0,0.3353673419575299,0.4967049060288016,0.13438660872246813,23430.50847457049 163 | 160,213.0,0.31559677813033926,0.5013424456919697,0.10474866050781124,35058.98305083881 164 | 161,286.0,0.33024164022455454,0.45203807664144496,-0.014372976432536018,21174.23728813037 165 | 162,345.5,0.31608494020014644,0.528435440566268,0.09357775570762318,25860.33898304447 166 | 163,298.5,0.33219428850378324,0.43446424212838664,0.08070001832924671,46513.89830507327 167 | 164,175.5,0.31242372467659263,0.5650475958018062,0.0531050138145726,15967.457627114705 168 | 165,269.0,0.33390285574810835,0.4327556748840615,-0.025284481083179593,47902.37288134412 169 | 166,230.5,0.313400048816207,0.5474737612887479,-0.008462905728527067,32108.474576263266 170 | 167,188.5,0.3238955333170613,0.5313644129851111,0.04416841926989279,25860.33898304447 171 | 168,164.0,0.3077861850134245,0.5772516475469855,0.08928373911958869,22389.15254236736 172 | 169,154.0,0.3146204539907249,0.5157432267512815,-0.09717470727122587,9025.084745763268 173 | 170,213.0,0.3019282401757383,0.5333170612643398,0.11879155964560059,26033.898305078324 174 | 171,151.0,0.2963143763729558,0.5699292164998779,-0.0072176859472959706,11454.915254237994 175 | 172,163.0,0.3077861850134245,0.5120820112277276,0.06500496979035442,19091.525423729992 176 | 173,250.0,0.31559677813033926,0.539663168171833,0.2684321060546761,19438.6440678038 177 | 174,168.5,0.29729070051257017,0.5630949475225775,0.2622378858873994,13016.949152539162 178 | 175,279.5,0.30803026604832806,0.6224066390041494,0.08601994324700231,31414.237288135108 179 | 176,277.5,0.3002196729314132,0.5909201855015865,0.20335566569455824,39050.847457626514 180 | 177,167.0,0.3046131315596778,0.5501586526726874,-0.02873459043307313,11975.593220338798 181 | 178,258.5,0.29607029533805224,0.585306321698804,0.5136023259308607,23083.3898305099 182 | 179,197.0,0.3146204539907249,0.48865023187698314,0.19844687568556396,17876.61016949263 183 | 180,201.0,0.2982670246521845,0.5057359043202343,0.1374569837123336,23430.50847457049 184 | 181,290.0,0.2909445936050769,0.586526726873322,0.24791300801672272,20306.440677961094 185 | 182,178.0,0.3151086160605321,0.5135464974371491,0.11349259590790252,16488.135593220086 186 | 183,376.5,0.3170612643397608,0.5328288991945326,0.04052130022969051,29157.96610169222 187 | 184,157.5,0.3055894556992922,0.5630949475225775,-0.01938415060191366,14231.864406784925 188 | 185,321.5,0.32413961435196487,0.49060288015621184,-0.07771118401326607,40265.7627118793 189 | 186,321.5,0.31169148157188187,0.4898706370515011,-0.012010674894565724,24645.42372880748 190 | 187,201.0,0.31364412985111056,0.5425921405906761,0.05770463897918462,15620.338983049403 191 | 188,195.5,0.30973883329265317,0.6243592872833781,0.1281472273759214,15273.220338983992 192 | 189,334.5,0.3202343177935074,0.4608249938979741,0.13164390950506583,25339.661016942904 193 | 190,286.0,0.3292653160849402,0.4571637783744203,0.004895579787301541,21347.79661017739 194 | 191,225.0,0.31559677813033926,0.5303880888454967,-0.11512819282917286,13884.745762711651 195 | 192,177.5,0.29924334879179887,0.5298999267756895,-0.14098090953076667,14058.305084742295 196 | 193,288.0,0.30168415914083474,0.5093971198437881,0.11005849496816567,14405.423728818889 197 | 194,224.5,0.29387356602391995,0.6329021235050036,0.2576425151578528,16835.254237288525 198 | 195,202.5,0.29973151086160604,0.5591896509641201,-0.06371037463343007,14578.983050848357 199 | 196,230.5,0.3212106419331218,0.5257505491823286,-0.193802023192496,15793.89830508572 200 | 197,214.5,0.3126678057114962,0.5477178423236515,-0.30323344893923665,16661.694915255266 201 | 198,169.0,0.3212106419331218,0.5203807664144496,0.15905100823118742,17355.93220338555 202 | 199,194.5,0.29387356602391995,0.5694410544300708,0.15182874063604598,14405.423728810007 203 | 200,179.0,0.28874786429094457,0.5462533561142299,-0.33330004790059464,7289.491525424179 204 | 201,248.5,0.2880156211862338,0.565779838906517,-0.02443848532901808,7636.6101694896415 205 | 202,243.0,0.2946058091286307,0.6060532096656089,-0.0509380883008116,10760.677966105675 206 | 203,80.5,0.30998291432755676,0.6060532096656089,-0.1360031352821077,3124.067796610121 207 | 204,251.0,0.30144007810593115,0.5447888699048083,0.13694649563577466,18744.406779656394 208 | 205,234.0,0.28874786429094457,0.525506468147425,0.1857276917119002,19959.322033893382 209 | 206,250.0,0.3055894556992922,0.5013424456919697,-0.18267381623346732,12322.71186440754 210 | 207,94.0,0.3087625091530388,0.5152550646814742,-0.18589588503012977,3297.6271186432546 211 | 208,293.5,0.26922138149865754,0.6092262631193556,-0.02985421327348107,12843.389830505306 212 | 209,352.5,0.30827434708323165,0.5638271906272883,0.27282471271526926,26381.016949146036 213 | 210,112.5,0.2828899194532585,0.5752989992677568,-0.2601011940950557,7983.728813557353 214 | 211,248.0,0.2948498901635343,0.5735904320234317,-0.3980988465660921,10066.44067796362 215 | 212,111.5,0.31193556260678545,0.48669758359775445,-0.09215673302613546,6768.813559320364 216 | 213,95.5,0.3026604832804491,0.4691237490846961,-0.017949237041026952,3644.7457627120893 217 | 214,124.5,0.3114474005369783,0.5530876250915304,0.04787766841127168,6595.2542372905755 218 | 215,199.5,0.3024164022455455,0.5230656577983891,0.05674336552021033,12322.71186440374 219 | 216,197.5,0.2533561142299243,0.7349279960947035,-0.3791510676656608,7463.050847458087 220 | 217,66.5,0.3190139126189895,0.5037832560410056,-0.28926392718523347,2950.508474575998 221 | 218,182.0,0.31388821088601415,0.6263119355626068,0.10485040663441803,15620.338983046995 222 | 219,102.0,0.31950207468879666,0.5184281181352209,-0.315462932261711,3818.305084745998 223 | 220,325.0,0.2989992677568953,0.643397608005858,0.36313982864471606,15099.661016950084 224 | 221,241.5,0.28972418843055897,0.5181840371003174,-0.1865507614236294,18397.288135588682 225 | 222,280.5,0.32072247986331465,0.5735904320234317,-0.2832808857430427,33149.8305084664 226 | 223,244.0,0.31584085916524285,0.5494264095679766,0.12628267512394942,12149.152542373631 227 | 224,155.0,0.29948742982670246,0.49743714913351234,0.2543513683014751,5553.89830508466 228 | 225,154.0,0.28118135220893337,0.5233097388332927,-0.13514035397446264,10413.55932203133 229 | 226,68.0,0.31584085916524285,0.4893824749816939,-0.13029526225427665,4686.1016949140985 230 | 227,147.0,0.29192091774469126,0.5621186233829631,0.20356842212995307,6421.694915254138 231 | 228,176.5,0.2946058091286307,0.5765194044422748,-0.29079593905453843,6421.694915254633 232 | 229,304.0,0.3290212350500366,0.5247742250427142,-0.20130980598060588,37315.25423727893 233 | 230,207.5,0.2640956797656822,0.6804979253112033,-0.1061225819050736,10587.118644067787 234 | 231,164.0,0.2931413229192092,0.5665120820112277,-0.011431120568466594,6595.2542372905755 235 | 232,279.0,0.3055894556992922,0.5391750061020258,0.05035805320316083,12843.389830509266 236 | 233,102.5,0.32584818159629,0.5152550646814742,-0.273387889058764,7810.1694915234975 237 | 234,255.0,0.29411764705882354,0.5008542836221626,-0.29678809470847334,34017.627118635675 238 | 235,159.0,0.21723212106419332,0.665853063216988,-1.3340443573371252,10587.118644067634 239 | 236,184.5,0.28362216255796924,0.5843299975591897,-0.060674390947377185,7289.491525424179 240 | 237,150.0,0.27605565047595804,0.6783011959970711,-0.4006125874674907,10413.55932203133 241 | 238,121.5,0.292653160849402,0.5845740785940933,-0.23830425165315736,12322.71186440374 242 | 239,112.5,0.29558213326824506,0.5589455699292165,-0.2317676442884849,11628.474576268318 243 | 240,302.0,0.2877715401513302,0.6602391994142055,-0.2717117561410131,39224.40677965134 244 | 241,65.5,0.31388821088601415,0.5240419819380034,-0.31721666098774204,7289.491525421931 245 | 242,183.5,0.2499389797412741,0.6097144251891629,-0.9371639738206621,11802.033898305812 246 | 243,83.5,0.30168415914083474,0.6241152062484745,-0.1377999572137664,2776.949152542544 247 | 244,276.0,0.27288259702221135,0.622650720039053,-0.1345356341451504,14752.542372882266 248 | 245,122.5,0.3165731022699536,0.48450085428362216,-0.05856882881523893,5553.898305083376 249 | 246,192.0,0.2750793263363437,0.5164754698559922,-0.34626077095842456,11975.593220338798 250 | 247,187.0,0.2928972418843056,0.5191603612399317,0.05380516017935465,12322.71186440659 251 | 248,253.5,0.3055894556992922,0.5579692457896022,0.03751182432332176,13537.627118644903 252 | 249,279.5,0.2745911642665365,0.6175250183060776,-0.23732438505257822,27769.491525434 253 | 250,405.5,0.2809372711740298,0.6441298511105688,0.11638621353092922,16141.016949152916 254 | 251,147.5,0.3053453746643886,0.5489382474981694,0.05159773737842811,10760.67796610236 255 | 252,191.0,0.3077861850134245,0.5494264095679766,0.113632020539745,18744.406779656394 256 | 253,246.0,0.2985111056870881,0.565779838906517,0.0619299064050665,23430.50847457049 257 | 254,99.0,0.32047839882841106,0.48303636807420064,-0.3471222684218669,3644.745762713213 258 | 255,159.0,0.2882597022211374,0.5565047595801806,-0.18641056787944785,10587.118644065185 259 | 256,169.0,0.31047107639736393,0.550402733707591,0.07584812526911718,11454.915254234464 260 | 257,209.5,0.31217964364168904,0.467415181840371,-0.13383812542404377,9545.762711862053 261 | 258,261.5,0.33585550402733705,0.514766902611667,-0.1529374649001519,10587.118644068449 262 | 259,120.0,0.2604344642421284,0.6412008786917257,-0.2745513514975018,7636.6101694896415 263 | 260,198.5,0.30656577983890654,0.5252623871125214,0.07664210568162383,9198.644067794341 264 | 261,204.5,0.3041249694898706,0.520136685379546,-0.09086872937489712,11802.033898302174 265 | 262,157.5,0.29948742982670246,0.5176958750305102,-0.24930882111640837,16314.576271182417 266 | 263,238.0,0.267756895289236,0.7039297046619478,-0.6438464916935696,18050.16949152097 267 | 264,213.0,0.3019282401757383,0.521357090554064,-0.30219454095088183,29505.084745755434 268 | 265,158.0,0.30168415914083474,0.557481083719795,-0.16468893669938775,10239.999999997475 269 | 266,238.0,0.288503783256041,0.557481083719795,-0.05817235516327104,9372.203389830363 270 | 267,214.0,0.3026604832804491,0.5130583353673419,0.24463854687008826,6074.576271184942 271 | 268,137.5,0.29192091774469126,0.5821332682450574,-0.13103680570031406,5553.898305083376 272 | 269,146.0,0.3202343177935074,0.48865023187698314,-0.29276084351928033,10413.55932203133 273 | 270,189.0,0.3024164022455455,0.5535757871613376,-0.22188246304668502,10240.000000000631 274 | 271,175.0,0.3021723212106419,0.49548450085428364,0.020577370605926713,6768.8135593224515 275 | 272,86.5,0.3026604832804491,0.6702465218452526,-0.2793013032442753,5206.779661015665 276 | 273,96.5,0.31242372467659263,0.5157432267512815,-0.010771747137440325,4165.4237288134955 277 | 274,81.0,0.29924334879179887,0.4776665853063217,-0.13847887311390522,3297.6271186432546 278 | 275,152.0,0.3046131315596778,0.5303880888454967,-0.2902096011651382,9545.762711862053 279 | 276,236.5,0.3431779350744447,0.5018306077617769,-0.08298460670164366,29157.966101687725 280 | 277,91.0,0.31925799365389307,0.5037832560410056,-0.33949023695834407,10413.55932203133 281 | 278,191.0,0.292653160849402,0.582377349279961,-0.1670326330213124,11454.915254234464 282 | 279,184.0,0.27068586770807906,0.5796924578960215,-0.4892480304992025,11628.474576271903 283 | 280,126.0,0.32584818159629,0.5152550646814742,0.00662576301165363,5033.22033898181 284 | 281,204.0,0.30607761776909936,0.5479619233585551,0.3040054212986431,6248.135593220242 285 | 282,143.5,0.25701732975347813,0.6646326580424701,-0.5009376344313776,6768.8135593224515 286 | 283,254.0,0.28508664876739076,0.577007566512082,-0.05437402039281126,29678.64406778929 287 | 284,157.0,0.231632902123505,0.64217720283134,-1.2230130440033702,10587.118644068449 288 | 285,277.5,0.3024164022455455,0.5872589699780327,-0.07019250597859399,12669.830508473404 289 | 286,130.5,0.29192091774469126,0.5818891872101538,-0.1883571618362803,5206.779661015665 290 | 287,127.5,0.31413229192091774,0.5230656577983891,-0.31195939575284104,8157.288135593723 291 | 288,253.0,0.24652184525262388,0.6980717598242616,-0.4801486178421585,20306.440677961094 292 | 289,92.5,0.28337808152306565,0.6272882597022211,-0.43486521751540347,5553.898305083376 293 | 290,133.5,0.27410300219672934,0.5901879423968758,-0.13537456755941346,6074.576271184942 294 | 291,248.5,0.2909445936050769,0.6004393458628264,0.1625718743186871,10760.67796610236 295 | 292,139.5,0.2982670246521845,0.5464974371491335,-0.46772698849773553,5727.457627118997 296 | 293,188.5,0.29753478154747376,0.5828655113497682,0.18259926732679269,10760.677966099041 297 | 294,224.0,0.2753234073712473,0.6399804735172077,-0.3481841003853402,29852.203389823146 298 | 295,498.5,0.3072980229436173,0.5899438613619722,0.44746315163918604,34885.423728804955 299 | 296,180.0,0.3019282401757383,0.5806687820356359,0.10858135821409186,16661.69491525013 300 | 297,163.0,0.2828899194532585,0.5482060043934587,-0.19035472215963756,8157.288135591209 301 | 298,264.0,0.288503783256041,0.6109348303636808,-0.04389753385842566,10760.67796610153 302 | 299,163.0,0.2970466194776666,0.5015865267268733,-0.18797542402714415,7115.932203388075 303 | 300,101.0,0.30656577983890654,0.520136685379546,-0.3571151388183231,6248.135593220724 304 | 301,581.0,0.19477666585306322,0.7722723944349524,2.184076080531281,35058.983050849616 305 | 302,217.0,0.3292653160849402,0.4498413473273127,0.04984613338982067,39745.08474575291 306 | 303,126.5,0.29777886258237735,0.5216011715889676,-0.14066049530938735,8157.288135591209 307 | 304,348.0,0.27312667805711494,0.6519404442274835,0.3154616536319146,31761.35593220351 308 | 305,79.5,0.31803758847937513,0.5108616060532096,-0.08668033643854081,3644.7457627109657 309 | 306,155.5,0.28118135220893337,0.6180131803758848,0.09229450001014637,8677.96610169545 310 | 307,513.5,0.16939223822309007,0.8342689773004638,2.360301388534201,32455.593220340983 311 | 308,1308.0,0.09738833292653161,0.8296314376372956,2.883260080458455,130516.61016947945 312 | 309,589.0,0.19746155723700268,0.7664144495972663,2.2148309945968285,40092.20338983066 313 | 310,189.0,0.300951916036124,0.546741518184037,-0.7287199215452653,18570.847457622538 314 | 311,162.5,0.3087625091530388,0.5672443251159385,-0.06958263978138465,8157.288135593095 315 | 312,89.5,0.3151086160605321,0.5250183060776178,-0.2699783367457087,5553.898305083376 316 | 313,99.5,0.31584085916524285,0.4871857456675616,-0.09146293428968641,4686.101694916988 317 | 314,93.5,0.30998291432755676,0.4691237490846961,-0.348311562178596,4165.423728815101 318 | 315,177.0,0.2948498901635343,0.5228215767634855,-0.029983998717955162,9719.322033898343 319 | 316,114.5,0.3251159384915792,0.4454478886990481,-0.25781979961959284,5901.016949152551 320 | 317,245.0,0.3058335367341958,0.5804247010007323,-0.10865786031280587,13190.508474573018 321 | 318,181.5,0.24676592628752747,0.8123016841591408,-1.08082888347581,18050.16949152097 322 | 319,189.0,0.26556016597510373,0.7183304857212595,0.5662324187160004,13537.627118640728 323 | 320,705.5,0.2643397608005858,0.7337075909201854,-0.5023343833082319,58836.61016949515 324 | 321,219.5,0.3353673419575299,0.46326580424701,0.06522079784900553,31587.796610161702 325 | 322,260.0,0.30607761776909936,0.5857944837686112,-0.08711290995816248,12149.152542373631 326 | 323,255.0,0.3041249694898706,0.4835245301440078,-0.14061371807370515,18223.728813554826 327 | 324,316.5,0.2982670246521845,0.5352697095435685,-0.056763556191520084,15620.338983046995 328 | 325,87.5,0.2880156211862338,0.64217720283134,-0.033795029585236794,5901.016949152906 329 | 326,215.0,0.2907005125701733,0.5320966560898218,0.06847012097833502,8504.406779658919 330 | 327,152.0,0.288503783256041,0.6136197217476203,-0.5647483261317174,7810.169491524702 331 | 328,457.0,0.1889187210153771,0.7827678789358067,1.9519003143125184,28463.7288135523 332 | 329,528.5,0.1484012692213815,0.7825237979009031,2.3075379424340006,38183.05084747175 333 | 330,418.0,0.2658042470100073,0.7080790822553088,0.28567477577603095,43389.83050847474 334 | 331,342.5,0.25286795216011715,0.665853063216988,-0.5736298112120413,30199.322033890858 335 | 332,164.5,0.29924334879179887,0.5818891872101538,-0.21618386047215962,7983.728813559815 336 | 333,88.0,0.3351232609226263,0.5069563094947522,-0.12157057001077948,4165.423728815101 337 | 334,126.5,0.3268245057359043,0.44642421283866246,-0.2788472287216202,6421.694915252653 338 | 335,135.5,0.3090065901879424,0.546741518184037,-0.21648585762349656,9198.644067794341 339 | 336,178.5,0.3055894556992922,0.5579692457896022,-0.02597153636702959,21521.355932198083 340 | 337,171.0,0.3307298022943617,0.45618745423480594,-0.13327928298513078,14405.423728810007 341 | 338,209.5,0.31608494020014644,0.5120820112277276,0.0808566659023391,6942.37288135636 342 | 339,100.0,0.3234073712472541,0.4779106663412253,0.02083532682026884,5901.016949152451 343 | 340,375.5,0.13692946058091288,0.8672199170124482,-1.7381457273231269,21694.91525423779 344 | 341,87.5,0.3041249694898706,0.5128142543324383,0.04107928158973627,5380.338983050765 345 | 342,229.5,0.3168171833048572,0.5220893336587747,-0.1127884429133088,31934.91525422941 346 | 343,187.5,0.3019282401757383,0.5377105198926043,-0.19954826024434302,12322.71186440754 347 | 344,178.5,0.3187698315840859,0.5801806199658287,0.18867770637706693,9545.762711862053 348 | 345,147.0,0.3058335367341958,0.49548450085428364,0.0664071152805323,9545.762711864996 349 | 346,181.5,0.3043690505247742,0.4852330973883329,-0.0485951239087597,36447.45762710965 350 | 347,203.0,0.3146204539907249,0.4691237490846961,-0.09108058492692281,29678.64406778929 351 | 348,154.5,0.29021235050036615,0.575787161337564,0.2055675799375737,16488.135593221356 352 | 349,251.5,0.2645838418354894,0.5989748596534049,-0.2996240351914982,6768.813559320364 353 | 350,232.5,0.3380522333414694,0.46448620942152796,-0.036890604993230255,23430.50847457049 354 | 351,159.0,0.26702465218452526,0.6590187942396876,-0.021709161468596753,7289.491525424179 355 | 352,155.5,0.28533072980229435,0.5230656577983891,-0.062277947924409924,7115.932203390269 356 | 353,259.5,0.30119599707102757,0.5860385648035148,-0.10920290469795962,39918.644067786765 357 | 354,220.0,0.292653160849402,0.5672443251159385,-0.05633869347304201,15620.338983046995 358 | 355,128.5,0.3380522333414694,0.46131315596778133,-0.05599617592253954,16835.254237289173 359 | 356,178.0,0.2838662435928728,0.5455211130095191,0.029337722094615885,12496.271186437596 360 | 357,104.0,0.34073712472540885,0.4574078594093239,-0.2076174866552565,5033.220338983058 361 | 358,159.0,0.2946058091286307,0.5545521113009519,0.02263086669620433,6074.576271186816 362 | 359,1097.5,0.3143763729558213,0.520136685379546,0.17262048612935615,95284.06779664542 363 | 360,390.0,0.27117402977788624,0.622650720039053,-0.06433843453210052,36447.457627118085 364 | 361,232.5,0.2704417866731755,0.6138638027825238,-0.2409114292734309,5901.016949151087 365 | 362,159.0,0.23822309006590187,0.6150842079570418,1.1317057215758104,10413.55932203454 366 | 363,340.0,0.26726873321942884,0.7322431047107639,-0.3838589007269864,51026.44067795351 367 | 364,212.5,0.3053453746643886,0.593605076885526,-0.012630215525483221,17876.610169487118 368 | 365,182.0,0.27996094703441543,0.5745667561630461,-0.9521975444821328,8504.406779661542 369 | 366,182.5,0.2982670246521845,0.5648035147669026,0.0004183815349501484,9198.644067794341 370 | 367,116.5,0.3165731022699536,0.4967049060288016,-0.058368324179831454,5033.22033898181 371 | 368,98.5,0.2789846228948011,0.585306321698804,0.07858394898716214,6768.813559320364 372 | 369,484.5,0.22797168659995118,0.7283378081523065,1.5483721404062438,41133.559322030094 373 | 370,86.0,0.3046131315596778,0.5277031974615572,-0.18667085877315628,6074.576271184942 374 | 371,195.0,0.2826458384183549,0.8337808152306566,0.8267947881866746,19091.52542372852 375 | 372,608.0,0.3087625091530388,0.5216011715889676,0.21768582943987272,32455.593220340983 376 | 373,242.0,0.30485721259458143,0.5281913595313644,0.021570402868055286,19265.08474576984 377 | 374,70.0,0.3290212350500366,0.43397608005857946,-0.12333011465802486,4686.1016949140985 378 | 375,736.0,0.11886746399804735,0.8215767634854771,2.661112796238886,123400.67796607126 379 | 376,191.5,0.29924334879179887,0.5623627044178667,0.011306302676018332,17355.932203396253 380 | 377,164.0,0.3004637539663168,0.5589455699292165,0.034661968289302625,9545.762711863525 381 | 378,193.0,0.29411764705882354,0.5630949475225775,0.03208785866106928,9372.203389828197 382 | 379,172.0,0.3055894556992922,0.543812545765194,-0.14664381761443177,19612.20338982567 383 | 380,83.5,0.31022699536246034,0.5030510129362948,-0.03671639984226368,3818.3050847471754 384 | 381,211.5,0.33561142299243346,0.406394923114474,0.31892946408245293,11454.915254234464 385 | 382,75.0,0.32658042470100074,0.4535025628508665,-0.09788508811200482,6421.694915252653 386 | 383,149.0,0.3019282401757383,0.49206736636563336,-0.11242820204068436,12496.271186437596 387 | 384,71.5,0.31047107639736393,0.550402733707591,-0.05311729067677878,3991.8644067799073 388 | 385,518.0,0.27068586770807906,0.5950695630949475,-0.10067926234177028,33496.94915254444 389 | 386,81.0,0.3151086160605321,0.5311203319502075,-0.4719548550646931,10587.118644065185 390 | 387,63.0,0.3202343177935074,0.44007810593116914,0.013766068854533839,7115.932203388075 391 | 388,242.0,0.292653160849402,0.6070295338052233,0.03413337859328219,20480.000000001262 392 | 389,265.0,0.2946058091286307,0.5381986819624115,0.38991542891589065,10587.118644065185 393 | 390,275.0,0.3185257505491823,0.46009275079326334,-0.061710753275538655,12496.271186441449 394 | 391,292.0,0.23822309006590187,0.7276055650475958,-0.8400447746639291,20653.559322028803 395 | 392,105.0,0.31803758847937513,0.4803514766902612,0.04714844290084312,5553.898305083376 396 | 393,167.0,0.29948742982670246,0.5862826458384184,-0.4046654510756718,10587.118644068449 397 | 394,233.5,0.2860629729070051,0.571637783744203,0.06965649621461743,8504.406779661009 398 | 395,232.5,0.2946058091286307,0.5513790578472053,0.031397651133071434,23430.508474577717 399 | 396,237.0,0.3053453746643886,0.4842567732487186,-0.007890063424731206,25860.33898304447 400 | 397,401.5,0.19355626067854528,0.8201122772760556,-1.952871740838662,21694.91525423194 401 | 398,87.0,0.3187698315840859,0.5064681474249451,-0.09714141218752505,7115.932203388075 402 | 399,93.5,0.33219428850378324,0.4586282645838418,0.0836471667718495,7115.932203389721 403 | 400,1344.0,0.23236514522821577,0.6939223822309006,1.4496565972230613,138847.4576270844 404 | 401,1196.5,0.21454722968025383,0.6741518184037101,1.3593332830338956,120450.16949153286 405 | 402,651.5,0.3507444471564559,0.3866243592872834,-0.5189794300449693,48075.932203377975 406 | 403,1170.0,0.3697827678789358,0.29216499877959484,-0.48304243450187184,170608.81355927995 407 | 404,394.5,0.29997559189650963,0.5460092750793263,0.1521641301821312,23430.50847457049 408 | 405,561.5,0.3600195264827923,0.4332438369538687,-0.10206376390521994,60051.525423714 409 | 406,693.5,0.3112033195020747,0.4078594093238955,-0.6693873598091287,63175.593220323404 410 | 407,1449.0,0.2096656089821821,0.6499877959482548,-1.3780134137281093,141971.52542373756 411 | 408,887.5,0.29802294361728093,0.5272150353917501,0.5220639131036561,72894.91525424179 412 | 409,1544.5,0.3292653160849402,0.5445447888699048,-0.38235247413870044,156029.83050848418 413 | 410,1067.5,0.29777886258237735,0.5875030510129363,-0.006265354056853621,101705.76271183933 414 | 411,674.5,0.34635098852819135,0.4535025628508665,0.2776928722432598,59877.96610168015 415 | 412,470.0,0.34293385403954113,0.3846717110080547,-0.42078561642080886,39050.84745764157 416 | 413,948.0,0.30851842811813524,0.42592140590676103,-0.8647765627160128,69250.16949150835 417 | 414,606.5,0.28166951427874054,0.5694410544300708,0.048988026256015435,80184.40677966597 418 | 415,1370.0,0.22333414693678302,0.6309494752257749,-1.382500907757351,151864.4067796704 419 | 416,487.0,0.23456187454234806,0.6851354649743715,-0.6061766963844488,38183.050847459985 420 | 417,353.5,0.3046131315596778,0.5848181596289969,-0.5441916584623355,31240.67796609399 421 | 418,1165.5,0.33902855748108374,0.4552111300951916,0.25055447260508357,115590.5084745834 422 | 419,1464.5,0.2662924090798145,0.5833536734195753,-1.0666508745647196,187096.94915249624 423 | 420,1078.5,0.3832072247986332,0.3131559677813034,-0.25929547727713137,80878.6440678016 424 | 421,1465.0,0.31047107639736393,0.5450329509397119,0.3133365739553642,166616.94915250127 425 | 422,427.0,0.26336343666097145,0.5845740785940933,-0.589169437804117,42869.15254238874 426 | 423,421.0,0.2704417866731755,0.6136197217476203,-0.8766659469624373,30719.999999992422 427 | 424,1814.5,0.2457896021479131,0.6634122528679521,-0.8684567622639437,188138.30508472837 428 | 425,534.5,0.32999755918965096,0.3973639248230412,-0.20395455921261949,50505.76271185195 429 | 426,335.5,0.30998291432755676,0.4476446180131804,-0.3981952148825258,39224.40677965134 430 | 427,1093.0,0.27092994874298265,0.5828655113497682,0.8526917038825765,96846.10169492122 431 | 428,646.0,0.386868440322187,0.31388821088601415,0.36277688379301226,58663.05084746124 432 | 429,490.5,0.296802538442763,0.4927996094703442,0.38679854328226926,31761.355932195554 433 | 430,527.5,0.35001220405174516,0.402245545521113,0.4256219097250366,58315.93220337545 434 | 431,961.0,0.30144007810593115,0.5958018061996583,0.26976930905207813,124094.91525420669 435 | 432,1711.5,0.25433243836953867,0.5772516475469855,-1.0435384105428396,340696.94915245834 436 | 433,1448.5,0.28972418843055897,0.5084207957041738,-0.9203548846823034,318828.47457619256 437 | 434,820.0,0.35684647302904565,0.41981938003417135,-0.34828772981255535,73242.03389833219 438 | 435,1392.5,0.2050280693190139,0.6673175494264095,1.7457668009767027,98234.57627116221 439 | 436,474.5,0.26873321942885037,0.6041005613863802,-0.9251475808898412,37835.9322033805 440 | 437,473.5,0.28972418843055897,0.5899438613619722,-0.017998242343641033,40439.3220339008 441 | 438,1012.0,0.31803758847937513,0.5447888699048083,0.48957588511994515,78101.69491525454 442 | 439,689.5,0.33390285574810835,0.4205516231388821,0.29221466340096397,69597.2881355935 443 | 440,1409.5,0.18794239687576275,0.6355870148889431,-1.580058301604012,150302.3728813652 444 | 441,1848.0,0.32413961435196487,0.46326580424701,0.44830993554006937,127739.66101695703 445 | 442,976.5,0.2743470832316329,0.5748108371979497,1.0107286520359187,91118.64406777413 446 | 443,619.5,0.3270685867708079,0.3812545765194044,-0.661614710068267,43563.38983052459 447 | 444,585.5,0.14791310715157432,0.7971686599951184,2.2676791104476424,53976.94915252906 448 | 445,450.0,0.32267512814254334,0.4459360507688553,-0.29952299381225617,28810.847457620013 449 | 446,615.5,0.32462777642177204,0.4732731266780571,-0.23696749595268657,55191.86440677881 450 | 447,1023.0,0.2914327556748841,0.6270441786673175,0.11436532955032434,72547.79661015159 451 | 448,1074.5,0.28313400048816206,0.6470588235294118,-0.11024895362736382,93201.35593220555 452 | 449,519.0,0.22455455211130096,0.7183304857212595,-1.2222634729519397,36273.898305075796 453 | 450,707.0,0.3055894556992922,0.4879179887722724,0.6981091346448879,64216.94915254633 454 | 451,1672.5,0.260678545277032,0.589455699292165,-0.7355448129325275,209138.98305086035 455 | 452,720.0,0.2809372711740298,0.5320966560898218,0.8724196701983471,58836.61016947701 456 | 453,1670.5,0.2479863314620454,0.593605076885526,-1.1575317042701723,415153.89830498234 457 | 454,884.0,0.2770319746155724,0.5928728337808152,0.7671068082813465,102399.99999997474 458 | 455,624.5,0.28166951427874054,0.5650475958018062,0.8834227533423057,50505.76271186752 459 | 456,1128.5,0.33390285574810835,0.4337319990236759,0.5730221749901714,80705.0847457428 460 | 457,375.5,0.31925799365389307,0.4913351232609226,-0.14706356119512373,21868.474576272536 461 | 458,763.0,0.3231632902123505,0.3978520868928484,-0.6179208078247034,56753.89830507075 462 | 459,1343.5,0.3348791798877227,0.47595801806199656,-0.6475897783481882,150823.05084742044 463 | 460,550.0,0.35879912130827435,0.3190139126189895,0.3748742559997964,52241.355932206614 464 | 461,246.0,0.37881376617036855,0.2931413229192092,0.30348876428930077,15273.220338988702 465 | 462,651.5,0.24603368318281668,0.6355870148889431,0.8321443349821458,75845.42372879485 466 | 463,1609.0,0.22504271418110813,0.5821332682450574,-1.2568810968074375,210006.77966096514 467 | 464,563.0,0.32267512814254334,0.44813278008298757,-0.024357120642087053,33149.830508474064 468 | 465,1536.0,0.3351232609226263,0.4288503783256041,-0.44806472973070005,160368.81355933193 469 | 466,1239.0,0.26751281425433243,0.5655357578716134,1.0918894277265705,148740.33898304857 470 | 467,852.5,0.33024164022455454,0.3888210886014157,-0.7530194862380961,63002.03389830897 471 | 468,335.5,0.23505003661215523,0.5184281181352209,1.1074396625496528,34017.62711865665 472 | 469,554.5,0.37466438857700757,0.3219428850378326,0.5542820341734657,65084.74576269581 473 | 470,1501.0,0.2577495728581889,0.5618745423480596,-0.009611638710854334,167311.18644067537 474 | 471,745.5,0.3278008298755187,0.5530876250915304,0.24008386610819554,73415.59322032088 475 | 472,1330.5,0.34220161093483037,0.39272638515987307,0.5339088675145014,215560.67796604853 476 | 473,1644.0,0.2933854039541128,0.5072003905296558,-0.7967008596554048,217816.94915248864 477 | 474,592.5,0.35660239199414207,0.34854771784232363,0.19244728945601727,74456.94915252402 478 | 475,1047.5,0.33243836953868683,0.36270441786673174,-0.7557480541649251,99102.3728813926 479 | 476,984.5,0.3168171833048572,0.48620942152794727,-0.04957717859799979,89209.49152542923 480 | 477,739.5,0.2892360263607518,0.5970222113741762,-0.9250494983835762,62134.23728812027 481 | 478,690.0,0.25506468147424943,0.6551134976812302,-0.9956775728798191,69423.7288135529 482 | 479,342.0,0.24652184525262388,0.525506468147425,1.1037662065393583,43563.38983049773 483 | 480,492.0,0.3295093971198438,0.4491091042226019,0.4545949689417624,69076.61016947449 484 | 481,1336.0,0.2933854039541128,0.5494264095679766,0.506536497404268,100317.2881355994 485 | 482,512.5,0.2865511349768123,0.5157432267512815,0.24267494218730348,55712.54237288479 486 | 483,1580.5,0.30827434708323165,0.41957529899926777,-0.7381550203525635,220073.22033899662 487 | 484,355.0,0.26336343666097145,0.6192335855504028,1.1872798058753329,18744.40677966217 488 | 485,590.5,0.3656333902855748,0.3617280937271174,0.2888638255841746,72374.23728811774 489 | 486,523.5,0.2584818159628997,0.6326580424701,-0.8878537395824276,38183.05084747175 490 | 487,1464.0,0.3473273126678057,0.5069563094947522,0.1808656661901858,145616.27118644965 491 | 488,1146.5,0.31022699536246034,0.46326580424701,0.7517702195200344,209659.66101689744 492 | 489,945.5,0.3436660971442519,0.5089089577739809,0.21655238406111885,61092.88135593244 493 | 490,1725.0,0.2753234073712473,0.589455699292165,-0.7589579000605426,200287.457627131 494 | 491,1009.5,0.2892360263607518,0.5240419819380034,0.8239357974915648,86606.10169491726 495 | 492,852.5,0.3907737368806444,0.34805955577251646,0.2605398194807477,60745.762711868156 496 | 493,1279.5,0.20258725896997803,0.8115694410544301,-0.7058223212908012,152037.96610170428 497 | 494,401.5,0.33707590920185504,0.4571637783744203,0.24369780411155645,29331.52542373062 498 | 495,876.5,0.3683182816695143,0.36441298511105685,-0.4727566126078412,94242.71186441259 499 | 496,433.0,0.3617280937271174,0.39492311447400535,0.046879961253473476,27595.93220339153 500 | 497,1359.0,0.2704417866731755,0.6282645838418355,-0.4681302476837636,243156.61016943154 501 | 498,1590.0,0.3055894556992922,0.4891383939467903,-0.6740339141930839,176856.9491525422 502 | 499,1396.0,0.2257749572858189,0.6067854527703197,-1.347758230265331,131037.2881356013 503 | -------------------------------------------------------------------------------- /Ch10/electricity.txt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PracticalTimeSeriesAnalysis/BookRepo/cb20c277addd0e02423b7f965d4114cc806c287a/Ch10/electricity.txt.gz -------------------------------------------------------------------------------- /Ch13/IledeFrance.csv: -------------------------------------------------------------------------------- 1 | Catégorie : Toutes les catégories 2 | 3 | Mois,grippe: (Île-de-France),grippe -aviaire -vaccin: (Île-de-France),grippe -aviaire -vaccin -porcine -porc -H1N1 -AH1N1 -A -mexicaine -Mexique -pandemie: (Île-de-France) 4 | 2004-01,7,5,5 5 | 2004-02,11,4,4 6 | 2004-03,3,1,1 7 | 2004-04,1,1,1 8 | 2004-05,1,1,1 9 | 2004-06,0,0,0 10 | 2004-07,1,1,1 11 | 2004-08,1,1,1 12 | 2004-09,2,1,1 13 | 2004-10,5,3,2 14 | 2004-11,4,2,2 15 | 2004-12,4,3,3 16 | 2005-01,5,4,4 17 | 2005-02,11,9,9 18 | 2005-03,4,3,3 19 | 2005-04,2,2,2 20 | 2005-05,2,1,1 21 | 2005-06,2,1,1 22 | 2005-07,1,0,0 23 | 2005-08,4,1,1 24 | 2005-09,10,3,3 25 | 2005-10,36,8,8 26 | 2005-11,14,4,4 27 | 2005-12,5,2,2 28 | 2006-01,12,4,4 29 | 2006-02,32,8,8 30 | 2006-03,24,6,5 31 | 2006-04,6,2,2 32 | 2006-05,4,1,1 33 | 2006-06,3,1,1 34 | 2006-07,1,1,0 35 | 2006-08,1,1,1 36 | 2006-09,2,1,1 37 | 2006-10,5,2,2 38 | 2006-11,5,2,2 39 | 2006-12,5,3,2 40 | 2007-01,6,4,4 41 | 2007-02,9,6,6 42 | 2007-03,3,2,2 43 | 2007-04,2,1,1 44 | 2007-05,1,1,1 45 | 2007-06,2,1,1 46 | 2007-07,2,1,1 47 | 2007-08,2,1,1 48 | 2007-09,3,1,1 49 | 2007-10,5,3,2 50 | 2007-11,4,2,2 51 | 2007-12,4,3,3 52 | 2008-01,8,7,7 53 | 2008-02,7,6,6 54 | 2008-03,3,2,2 55 | 2008-04,2,1,1 56 | 2008-05,1,1,1 57 | 2008-06,1,1,1 58 | 2008-07,1,1,1 59 | 2008-08,1,1,1 60 | 2008-09,2,1,1 61 | 2008-10,4,2,2 62 | 2008-11,4,2,2 63 | 2008-12,6,5,5 64 | 2009-01,9,8,8 65 | 2009-02,4,3,3 66 | 2009-03,2,1,1 67 | 2009-04,40,38,7 68 | 2009-05,33,31,8 69 | 2009-06,24,22,5 70 | 2009-07,44,41,10 71 | 2009-08,64,59,15 72 | 2009-09,93,86,20 73 | 2009-10,40,35,8 74 | 2009-11,100,81,14 75 | 2009-12,76,64,12 76 | 2010-01,17,15,4 77 | 2010-02,5,5,2 78 | 2010-03,3,3,1 79 | 2010-04,2,2,1 80 | 2010-05,2,2,1 81 | 2010-06,1,1,1 82 | 2010-07,1,1,1 83 | 2010-08,2,1,1 84 | 2010-09,3,2,1 85 | 2010-10,4,2,2 86 | 2010-11,3,2,2 87 | 2010-12,7,6,5 88 | 2011-01,12,12,10 89 | 2011-02,6,6,5 90 | 2011-03,2,2,2 91 | 2011-04,2,2,1 92 | 2011-05,1,1,1 93 | 2011-06,1,1,1 94 | 2011-07,1,1,1 95 | 2011-08,1,1,1 96 | 2011-09,2,2,1 97 | 2011-10,3,2,2 98 | 2011-11,4,3,3 99 | 2011-12,4,3,3 100 | 2012-01,4,4,3 101 | 2012-02,10,10,9 102 | 2012-03,6,6,5 103 | 2012-04,2,2,2 104 | 2012-05,1,1,1 105 | 2012-06,1,1,1 106 | 2012-07,1,1,1 107 | 2012-08,1,1,1 108 | 2012-09,2,2,2 109 | 2012-10,4,3,3 110 | 2012-11,4,3,3 111 | 2012-12,8,7,6 112 | 2013-01,12,11,10 113 | 2013-02,15,15,14 114 | 2013-03,6,6,5 115 | 2013-04,4,3,3 116 | 2013-05,2,2,2 117 | 2013-06,1,1,1 118 | 2013-07,1,1,1 119 | 2013-08,1,1,1 120 | 2013-09,2,2,2 121 | 2013-10,4,3,3 122 | 2013-11,4,3,3 123 | 2013-12,5,4,4 124 | 2014-01,5,5,5 125 | 2014-02,9,9,8 126 | 2014-03,4,4,4 127 | 2014-04,2,2,2 128 | 2014-05,1,1,1 129 | 2014-06,1,1,1 130 | 2014-07,1,1,1 131 | 2014-08,2,1,1 132 | 2014-09,2,2,2 133 | 2014-10,5,4,3 134 | 2014-11,5,3,3 135 | 2014-12,6,5,5 136 | 2015-01,13,13,12 137 | 2015-02,26,26,24 138 | 2015-03,8,8,7 139 | 2015-04,3,3,3 140 | 2015-05,2,2,2 141 | 2015-06,1,1,1 142 | 2015-07,1,1,1 143 | 2015-08,1,1,1 144 | 2015-09,3,2,2 145 | 2015-10,5,3,3 146 | 2015-11,5,3,3 147 | 2015-12,7,4,4 148 | 2016-01,8,6,6 149 | 2016-02,15,14,13 150 | 2016-03,15,14,14 151 | 2016-04,6,5,5 152 | 2016-05,2,2,2 153 | 2016-06,2,2,1 154 | 2016-07,1,1,1 155 | 2016-08,1,1,1 156 | 2016-09,2,2,2 157 | 2016-10,6,4,4 158 | -------------------------------------------------------------------------------- /Ch13/empty.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Code for Practical Time Series Analysis 2 | 3 | Welcome. This git repository contains some (but not all) code that you will encounter in Practical Time Series Analysis. Over time this repository will expand to cover more of the material from the book and also to include extra examples. 4 | 5 | Comments and corrections are welcome. Please either submit a pull request or contact me via email at author's first name [DOT] A (my middle initial) [DOT] author's last name at gmail. 6 | 7 | I would also mention that much of the work on this book relates to earlier tutorials I have given. I link below to some YouTube videos showing these tutorials. 8 | 9 | ##### General tutorials: 10 | * Time Series Analysis with Python (SciPy 2016) (4 hours) (https://www.youtube.com/watch?v=JNfxr4BQrLk&t=10138s) 11 | * Time Series Analysis with Python (PyCon 2017) (3 hours) (https://www.youtube.com/watch?v=zmfe2RaX-14&t=8056s) 12 | * Modern Time Series Analysis (SciPy 2019) (4 hours) (https://www.youtube.com/watch?v=v5ijNXvlC5A&t=3813s) 13 | 14 | ##### Relevant special interest tutorials: 15 | * Irregular Time Series and How to Whip Them (PyData London 2016) (29 minutes) (https://www.youtube.com/watch?v=E4NMZyfao2c) 16 | * NoSQL Python: making data frames work for you in a non-rectangular world (PyData Amsterdam 2016) (35 minutes) (https://www.youtube.com/watch?v=QYtE-Irbd7E) 17 | 18 | 19 | Thanks for taking a look and thanks for your patience as I build out this repo. ~ Aileen 20 | --------------------------------------------------------------------------------