This file contains 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
# From https://github.com/ajfriend/h3_example_package | |
import numpy as np | |
from h3_example_package.geo import latlng_to_cell_vect | |
from h3 import api | |
N = 100000 | |
lats, lngs = np.random.uniform(0, 90, N), np.random.uniform(0, 90, N) | |
res = 9 |
This file contains 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
#!/usr/bin/env python3 | |
"""Demonstration of why you shouldn't set numpy.random.seed, and what you should do instead""" | |
import numpy as np | |
# When setting a seed, you usually mean "make things deterministic". | |
# However, because the Global numpy seed is _shared_, it is not a reliable source to guarantee deterministic outcomes. | |
# For example, assume we want to use numpy's choice, to choose five random numbers from an array: |
This file contains 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
#!/usr/bin/env python | |
"""Collect and parse data from Gsheet | |
Read spreadsheet from https://docs.google.com/spreadsheets/d/{SHEET_ID} | |
and parse as a polars DataFrame. | |
This example is using a benign sheet of junk from | |
https://docs.google.com/spreadsheets/d/1cFVczEL7oznX_G-_VyJv5tgkEPmoVHRsGanzMj1O4nM | |
but should give you the idea. |
This file contains 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
#!/usr/bin/env python3 | |
""" | |
Example of common pendulum use cases | |
Author: jongbin.jung | |
""" | |
import pandas as pd | |
import pendulum |
This file contains 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
results <- foreach(i=1:1000, .combine = bind_rows) %:% | |
foreach(method=c("binomial", "quasibinomial"), .combine = bind_rows) %dopar% { | |
beta <- 0.1 | |
df <- data.frame(id = rep(1:1000, 2)) %>% | |
mutate(m = rnorm(2000, 0, 1), | |
x = rnorm(2000, m, 2), | |
e = rnorm(2000, 0, beta / 2), | |
y = inv_logit(1 + beta*x+e)) %>% |
This file contains 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
# Assuming a (logistic) model with k features fit in R with the variable name "model", | |
# generate a simple rule that uses integers in the range [-M, M]: | |
# (note that M is set to 3 in this example) | |
M <- 3 | |
model_coefs <- coef(model) | |
scaled_coefs <- (model_coefs / max(model_coefs)) * M | |
rounded_coefs <- round(scaled_coefs) | |
# The k features to be included in the initial model is best determined by domain expertise, | |
# i.e., what are the minimal features that expert(s) in the field believes to be predictive |
This file contains 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("ggplot2") | |
#' Draw Normal Distribution Density with an area shaded in. | |
#' | |
#' @param lb Lower bound of the shaded area. Use \code{-Inf} for a left tail. | |
#' @param ub Upper bound of the shaded area. Use \code{Inf} for a right tail. | |
#' @param mean Mean of the normal distribution | |
#' @param sd Standard deviation of the normal distribution | |
#' @param limits Lower and upper bounds on the x-axis of the area displayed. | |
#' @return ggplot object. |