Skip to content

Instantly share code, notes, and snippets.

View coppeliaMLA's full-sized avatar

coppelia machine learning and analytics coppeliaMLA

View GitHub Profile
@coppeliaMLA
coppeliaMLA / bootstrap.ipynb
Last active March 15, 2022 13:08
bootstrap.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@coppeliaMLA
coppeliaMLA / binDiff.R
Created March 21, 2014 08:14
A function that gives the probability mass function for the difference between to binomially distributed random variables
modBin<-function(k, n, p){
if (k<=n) {
return(dbinom(k, n, p))
}
else {
return(0)
}
}
@coppeliaMLA
coppeliaMLA / Readme.md
Last active October 5, 2017 17:22
ROI Fan

Return on investment is often measured as revenue divided by costs, sometimes expressed as a percentage. For example if a marketing campaign cost £10K but brought in £20K of additional revenue then the ROI is 200%. Now if you are just given the ROI you'll find you are missing any of idea of scale. The same ROI could be achieved with a revenue of £200 and with one of £200 million. So it would be nice to see cost, revenue and ROI visualised all in one go. There are a few ways to do this but after playing around I came up with the following representation which personally I like the best. It's a simple scatterplot of cost against revenue but since all points on straight lines radiating from the origin have the same ROI it's easy to overlay that information. If r is the ROI the the angle of the corresponding spoke is arctan(r).

Note you can drag about the labels. That's my preferred solution for messy scatterplot labelling.

#Test imports
import urllib2, ssl, json, time, re
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.support.ui import Select
#Test urllib2
import urllib2
response = urllib2.urlopen('https://en.wikipedia.org/wiki/Test', context=ssl.SSLContext(ssl.PROTOCOL_TLSv1))
@coppeliaMLA
coppeliaMLA / finSim.R
Last active September 22, 2016 09:07
Uncertainty in a financial model
#First we are going to set up probaility distributions for our beliefs about the inputs
#We've been told ARPU is about £7 and it's very unlikely to be higher than £10 or lower than £4
#So we'll go for a normal distribution centred at 7 with 5% and 95% quantiles at 4 and 10
#Show how we get the variance
arpu.sd<-3/1.96
x<-seq(0, 15,by=0.5)
d<-dnorm(x, 7, arpu.sd)
plot(x, d, type='l')
<head>
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.1/d3.min.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.16/d3.min.js"></script>
<style> #mapid {
height: 800px;
} </style>
</head>
<body>
@coppeliaMLA
coppeliaMLA / arm.ino
Created July 13, 2016 15:56
Contro MeArm
#include <Servo.h>
Servo middle, left, right, claw ; // creates 4 "servo objects"
//positions 30, 45, 60, 75, 90, 105, 120, 135, 150
void setup()
{
middle.attach(8);
left.attach(10);
<head>
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.16/d3.min.js"></script>
<style> #mapid {
height: 800px;
} </style>
</head>
<body>
<head>
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.16/d3.min.js"></script>
<style> #mapid {
height: 800px;
} </style>
</head>
<body>
@coppeliaMLA
coppeliaMLA / tree.json
Last active August 29, 2015 14:17
Example json for tree visualisations
{
"name": "root",
"visits": "202K",
"children": [
{
"name": "purpledog.com",
"visits": "50K"
},
{
"name": "squishedfish.co.uk",