Skip to content

Instantly share code, notes, and snippets.

View ESeufert's full-sized avatar

Eric Benjamin Seufert ESeufert

View GitHub Profile
@ESeufert
ESeufert / LTV_and_Retention_Curves.py
Created January 14, 2019 16:44
Showcasing how LTV curves are dependent on Retention Curves
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import pandas as pd
import numpy as np
import random
def build_userbase( n, payer_percentage ):
users = pd.DataFrame( columns=[ "user", "payer", "payment_probability", "payment" ] )
for x in range( 1, n + 1 ):
payer = True if random.randint( 1, 100 ) <= ( payer_percentage * 100 ) else 0
# I had an annoying situation where I wanted a multi-chart matplotlib chart to look symmetrical given some number of max
# rows and columns
# eg. if I have 9 graphs I want to plot and the max number of (rows, columns) for the chart is (4, 4),
# I don't want 2 rows with 5 charts on the top and 4 on the bottom;
# I want 3 rows with 3 charts per row
# this algorithm returns a tuple of rows, columns given some parameters:
# this_length is the number of charts to plot
# max_cols is the maximum number of columns the chart can have (the matplotlib max is 4)
# max_rows is the maximum number of rows the chart can have (matplotlib max is 4)
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import matplotlib.colors as pltcolors
import pandas as pd
import numpy as np
import random
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import colors as mcolors
from matplotlib import cm
from beautifultable import BeautifulTable
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model import Ridge
from sklearn.preprocessing import PolynomialFeatures
from sklearn.pipeline import make_pipeline
from scipy.optimize import curve_fit
import statsmodels.stats.api as sms
import math
import operator
@ESeufert
ESeufert / index.html
Last active April 14, 2018 18:19
A simple line chart example using D3.js
<html>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<head>
<title>D3.js Dashboard Introduction</title>
<script src="http://d3js.org/d3.v2.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js"></script>
<script>
function getMaxObjectValue(this_array, element) {
<html>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<head>
<title>Comparison -- Mobile Handset Manufacturers and Platforms, Q1 2013 and Q1 2013</title>
<link href="http://nvd3.org/src/nv.d3.css" rel="stylesheet">
<link href="http://nvd3.org/css/common.css" rel="stylesheet">
<link href="http://nvd3.org/css/syntax.css" rel="stylesheet">
<script type="text/javascript" src="http://d3js.org/d3.v2.js"></script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>
Minimum Viable Metrics dashboard template - ufert.se
</title>
<link href="https://raw.github.com/ESeufert/MVM-Dashboard-Template/master/nvd3-master/src/nv.d3.css" rel="stylesheet" type="text/css">
@ESeufert
ESeufert / tweetScroll.class.php
Created October 25, 2012 19:21
tweetScroll -- a PHP class for archiving Twitter timelines
<?php
class tweet_scroll {
/******************************************************************
** database access constants **
** edit these **
******************************************************************/
private $dbName = 'YOUR MYSQL DATABASE NAME';
private $dbHost = 'YOUR MYSQL DATABASE HOST';
private $dbUser = 'YOUR MYSQL DATABASE USERNAME';
@ESeufert
ESeufert / index.html
Created August 23, 2012 07:59
A D3.js dashboard with a console for selecting dimensions
<html>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<head>
<title>D3.js Dashboard Introduction</title>
<script src="http://d3js.org/d3.v2.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js"></script>
<script>
function getMaxObjectValue(metric, graph_metric) {
@ESeufert
ESeufert / index.html
Created August 21, 2012 19:38
A set of line charts using D3.js
<html>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<head>
<title>D3.js Dashboard Introduction</title>
<script src="http://d3js.org/d3.v2.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js"></script>
<script>
function getMaxObjectValue(metric, graph_metric) {