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
#================================================= | |
# geom_line() + geom_ribbon() | |
#================================================= | |
# plots by group | |
plot_by_group <- function(df, x, colour) { | |
# create the summary data using # group_prop() | |
df_summary <- df %>% | |
dplyr::filter(!is.na({{ colour }})) %>% | |
group_prop({{ x }}, {{ colour }}) | |
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
group_prop <- function(df, ...) { | |
# enquo the dots | |
vars <- enquos(...) | |
# count then calculate | |
# proportions | |
df_count <- df %>% | |
count(!!!vars) | |
if (length(vars) > 1) { |
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
def partial_dependency_data(df, model, col, values, sample_fraction = 0.1): | |
# empty list for predictions | |
avg_predictions = list() | |
# take a sample of the data to use | |
df_sample = df.sample(fraction = sample_fraction) | |
# loop through the values | |
for val in values: |
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 Rscript | |
# to run from command line: | |
## chmod +x knit_dir.R | |
## ./knit_dir.R <dir-name> | |
# from https://stackoverflow.com/a/49950761 | |
# to avoid conflicts between packages | |
# breaking things | |
clean_search <- function() { |
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
import pandas as pd | |
from faker import Faker | |
# set the seed | |
Faker.seed(10) | |
# set the locale to GB | |
fake = Faker("en_GB") | |
# how many customers to fake |
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
import timeit | |
import numpy as np | |
from faker import Faker | |
# create the faker object | |
fake = Faker() | |
# np.random_choice function | |
def np_choice(N=1000): | |
np.random.choice(N+1, N, replace = False) |
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
\documentclass{article} | |
\usepackage{pdfpages} | |
\begin{document} | |
\includepdf[pages={30, 31, 32, 37}]{/path/to/file} | |
\end{document} |
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
# R ------------------------- | |
x = matrix(c(1,2,0, 4,3,7), ncol = 3, byrow = T) | |
x | |
# [,1] [,2] [,3] | |
# [1,] 1 2 0 | |
# [2,] 4 3 7 | |
# row means (NB: R indexes from 1) | |
> apply(x, MARGIN = 1, mean) | |
# 1.000000 4.666667 |
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
# Dependencies ---------------------- | |
import math | |
import shap | |
import matplotlib.pyplot as plt | |
# shap_dependence_plot_grid --------- | |
def shap_dependence_plot_grid(cols, | |
shap_values, | |
X, | |
interaction_index = None, |
OlderNewer