This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(geojsonsf) | |
| library(sf) | |
| library(rayrender) | |
| #Data source: https://github.com/telegeography/www.submarinecablemap.com | |
| cables = geojson_sf("cable-geo.json") | |
| cablescene = list() | |
| counter = 1 | |
| for(i in 1:length(cables$geometry)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(rayshader) | |
| library(rayrender) | |
| popdata = raster::raster("gpw_v4_population_density_rev11_2020_15_min.tif") | |
| population_mat = rayshader:::flipud(raster_to_matrix(popdata)) | |
| above1 = population_mat > 1 | |
| above5 = population_mat > 5 | |
| above10 = population_mat > 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(raster) | |
| library(rayshader) | |
| #Load QGIS georeference image (see https://www.qgistutorials.com/en/docs/3/georeferencing_basics.html) | |
| testindia = raster::stack("1870_southern-india_modified.tif") | |
| #Set bounding box for final map (cut off edges without data, introduced via reprojection) | |
| india_bb = raster::extent(c(68,92,1,20)) | |
| cropped_india = raster::crop(testindia, india_bb) | |
| #Convert to RGB array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Calibration and Holdouts periods for data split | |
| date_start = ['2013-04-01','2014-04-01','2015-04-01','2016-04-01'] | |
| calibration_period_end = ['2015-03-31','2016-03-31','2017-03-31','2018-03-31'] | |
| date_end = ['2016-03-31','2017-03-31','2018-03-31','2019-03-31'] | |
| #Arrays where to store the results of cross validation | |
| accuracies_1y = [] | |
| holdouts_1y = [] | |
| predictions_1y = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| from scipy.stats import poisson,expon,nbinom | |
| poisson_lambda = 4.3 | |
| p_arr = [] | |
| distribution = poisson(poisson_lambda) | |
| for transactions in range(0,10): | |
| p_arr.append(distribution.pmf(transactions)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # taken from https://medium.com/@pouryaayria/k-fold-target-encoding-dfe9a594874b | |
| from sklearn import base | |
| from sklearn.model_selection import KFold | |
| class KFoldTargetEncoderTrain(base.BaseEstimator, | |
| base.TransformerMixin): | |
| def __init__(self,colnames,targetName, | |
| n_fold=5, verbosity=True, | |
| discardOriginal_col=False): | |
| self.colnames = colnames |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(tigris) | |
| library(tidycensus) | |
| library(tidyverse) | |
| library(sf) | |
| ma_income <- get_acs(geography = "county subdivision", | |
| variables = "B19013_001", | |
| state = "MA") | |
| ma_subs <- county_subdivisions(state = "MA", cb = TRUE, class = "sf") %>% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Only including this file so the title of the gist isn't `.gitignore` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
NewerOlder