source: https://bradleyboehmke.github.io/HOML/iml.html
Assumptions:
- Every model is linear on a local scale;
- It is possible to fit a simple surrogate model around a single observation that will mimic how the global model behaves at the locality;
library(tidyverse) | |
library(tidymodels) | |
sf_trees <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-01-28/sf_trees.csv") | |
trees_df <- sf_trees %>% | |
mutate( | |
legal_status = case_when( | |
legal_status == "DPW Maintained" ~ legal_status, | |
TRUE ~ "Other" |
source: https://bradleyboehmke.github.io/HOML/iml.html
Assumptions:
# %% | |
import configparser | |
import mysql.connector | |
from mysql.connector import Error | |
import pandas as pd | |
from openpyxl import load_workbook | |
from openpyxl.utils.dataframe import dataframe_to_rows | |
config = configparser.ConfigParser() | |
config.read("config.ini") |
# %% | |
import configparser | |
import pandas as pd | |
import smtplib | |
from socket import gaierror | |
from email import encoders | |
from email.mime.base import MIMEBase | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText |
library(tidyverse) | |
library(rlang) | |
set.seed(123) | |
df <- tibble(id = rep(c(1:2), 10), | |
grade = sample(c("A", "B", "C"), 20, replace = TRUE)) | |
df %>% | |
group_by(id) %>% | |
summarise( |
library(tidyverse) | |
library(janitor) | |
library(EnvStats) | |
library(infer) | |
library(ggthemes) | |
set.seed(123) | |
old = theme_set(theme_minimal(base_family = "Noto Sans CJK SC") + | |
theme(legend.position = "top")) | |
# DID ---- |
library(feather) | |
library(dplyr) | |
library(purrr) | |
library(furrr) | |
library(uaparserjs) | |
raw <- feather::read_feather("raw.feather") %>% | |
`[[`('ua') %>% | |
purrr::discard(is.na) %>% | |
unique() |
library(tidyverse) | |
library(ggthemes) | |
library(lubridate) | |
library(gganimate) | |
# ggplot theme | |
old <- theme_set( | |
theme_minimal() + | |
theme( | |
text = element_text(family = 'Menlo'), |
set.seed(1234) | |
vec = c(13.1, 7.5, 4.4, 10.0, 7.8, 3.4, 3.5) / 100 | |
rb = EnvStats::ebeta(vec) | |
alpha = rb$parameters['shape1'] | |
beta = rb$parameters['shape2'] | |
x <- rbeta(1000, shape1 = alpha, shape2 = beta) | |
hist( | |
x, |
cuts = 0.8 # cutoff level | |
maxN = 100 # number of trials | |
run_game <- function(vec, cutoff, N) { | |
# browser() | |
if (length(vec) > N) { | |
return(vec) | |
} | |
pass = ifelse(mean(vec) >= cutoff, 0, 1) | |
vec = c(vec, pass) |