Skip to content

Instantly share code, notes, and snippets.

View AdamSpannbauer's full-sized avatar
👀
¯\_(ツ)_/¯

Adam Spannbauer AdamSpannbauer

👀
¯\_(ツ)_/¯
View GitHub Profile
@AdamSpannbauer
AdamSpannbauer / example_default_dict.py
Created January 22, 2020 11:53
Example for default dict to handle missing keys.
from collections import defaultdict
import numpy as np
def api_call(response_ok=True):
if response_ok:
return {'Released': 2010, 'Ratings': [{'Value': 98}]}
else:
return defaultdict(lambda: np.nan)
@AdamSpannbauer
AdamSpannbauer / print_vif.py
Last active September 1, 2020 14:05
VIF utility function for checking multicollinearity with stats models
import warnings
import statsmodels.api as sm
from statsmodels.stats.outliers_influence import variance_inflation_factor
def print_vif(x):
"""Utility for checking multicollinearity assumption
:param x: input features to check using VIF. This is assumed to be a pandas.DataFrame
:return: nothing is returned the VIFs are printed as a pandas series
("exit" to quit) Question: What market does FitBit compete in?
Search Rank Squad Rank Combined Rank Answer Context
0 2.0 6.0 1.5 crowded market ... rather crowded ma...
1 7.0 1.0 1.5 oncology ...te in the oncology ...
2 8.0 3.0 3.0 streaming services market ...trate the streaming ...
3 5.0 7.0 4.0 leash ...ck a long leash. Boe...
4 4.0 9.0 5.0 iPhones ...io of new iPhones - ...
5 1.0 13.0 6.5 wearables ...hough, is wearables,...
6 9.0 5.0 6.5 murky ...'re in a "murky" mar...
7 15.0 2.0 8.0 ad market ...ce in the ad market ...
>>> from whoosh.analysis import StandardAnalyzer
>>>
>>> [token.text for token in StandardAnalyzer()("This is an example analysis")]
@AdamSpannbauer
AdamSpannbauer / help2.R
Last active May 2, 2019 17:34
Experiment utility function to display docstring-esque help for R functions in Global Environment
# Experimental utility function
message("--------------------------------------------------------------------------------\n")
message("Overwriting `?` function with custom utility to display in memory function help.\n")
message("--------------------------------------------------------------------------------\n\n")
help2 = function(f, ...) {
#' Extend `help()` to show in memory function documentation
#'
#' @details Supports python docstring-esque roxygen documentation.
@AdamSpannbauer
AdamSpannbauer / diamond_problem.py
Created January 25, 2019 12:56
demonstrating diamond problem stuff with super in python
class A:
def x(self):
print('x: A')
class B(A):
def x(self):
super().x()
print('x: B')
@AdamSpannbauer
AdamSpannbauer / gganimate_heart.R
Last active February 10, 2022 14:40
animated heart using the R package gganimate
library(ggplot2)
library(gganimate)
library(data.table)
gen_heart_y = function(x, a) {
# source: https://i.imgur.com/avE8cxJ.gifv
(x^2)^(1 / 3) + 0.9 * (3.3 - x^2)^(1 / 2) * sin(a * pi * x)
}
heart_dt_list = lapply(seq(1, 15, by = 0.1), function(a) {
@AdamSpannbauer
AdamSpannbauer / r6_fractal_tree.R
Last active August 16, 2021 21:13
R6 Fractal Tree
library(R6)
library(ggplot2)
library(uuid)
options(stringsAsFactors = FALSE)
branch_base = R6Class('branch_base',
public = list(
start_x = NA_integer_,
start_y = NA_integer_,
end_x = NA_integer_,
@AdamSpannbauer
AdamSpannbauer / fractal_tree_gganimate.R
Created July 25, 2018 02:00
Create/animate fractal trees at various angles for branch splits
# Create/animate fractal trees at various angles for branch splits
library(gganimate)
library(ggplot2)
library(uuid)
options(stringsAsFactors = FALSE)
# create line segment from (0, 0) to (0, len) to be trunk of fractal tree
create_trunk = function(len = 1) {
end_point = c(0, len)
# Create/Draw a Binary Fractal Tree
library(ggplot2)
library(uuid)
options(stringsAsFactors = FALSE)
# create line segment from (0, 0) to (0, len) to be trunk of fractal tree
create_trunk = function(len = 1) {
end_point = c(0, len)
trunk_df = data.frame(x=c(0, 0),