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;
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) |
| ## the game goes like this, | |
| ## head +1 point and tail -1 point | |
| ## we flip 3 coins and count the score | |
| ## is there a correlation between them? | |
| library(tidyverse) | |
| library(ggthemes) | |
| set.seed(1234) | |
| coins = 4 |