Skip to content

Instantly share code, notes, and snippets.

import networkx as nx
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Multigraph example
G = nx.MultiGraph()
G.add_nodes_from([1, 2, 3])
@tomron
tomron / sprt.py
Last active April 30, 2019 09:58
Sequential probability ratio test implementation (https://en.wikipedia.org/wiki/Sequential_probability_ratio_test) for exponential distribution. Usage - `t = sprt.SPRT(0.05, 0.8, 1, 2); t.test([1, 2, 3, 4, 5])`
import numpy as np
"""
Implements Sequential probability ratio test
https://en.wikipedia.org/wiki/Sequential_probability_ratio_test
"""
class SPRT:
def __init__(self, alpha, beta, mu0, mu1):
@tomron
tomron / sprt.py
Created April 30, 2019 09:38
Sequential probability ratio test
import numpy as np
"""
Implements Sequential probability ratio test
https://en.wikipedia.org/wiki/Sequential_probability_ratio_test
"""
class SPRT:
def __init__(self, alpha, beta, mu0, mu1):
@tomron
tomron / welchtest.py
Created August 6, 2018 12:13
welchtest.py - based on the lazy programmer ttest implementation (https://github.com/lazyprogrammer/machine_learning_examples/blob/master/ab_testing/ttest.py). Numbers are not exactly the same but I suspect it have to do with rounding issues
import pandas as pd
import numpy as np
from scipy import stats
input_file='advertisement_clicks.csv'
df = pd.read_csv(input_file)
a = df[df['advertisement_id']== 'A']['action'].tolist()
@tomron
tomron / welchtest.py
Created August 6, 2018 12:11
welchtest
import pandas as pd
import numpy as np
from scipy import stats
input_file='advertisement_clicks.csv'
df = pd.read_csv(input_file)
a = df[df['advertisement_id']== 'A']['action'].tolist()
@tomron
tomron / MergeMapUDAF.java
Created July 20, 2017 06:49
Merge Map Spark User Defined Aggregation function - merge two maps of type <String, Long> to one Map.
package com.tomron;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.expressions.MutableAggregationBuffer;
import org.apache.spark.sql.expressions.UserDefinedAggregateFunction;
import org.apache.spark.sql.types.DataType;
import org.apache.spark.sql.types.DataTypes;
import org.apache.spark.sql.types.StructField;
import org.apache.spark.sql.types.StructType;
@tomron
tomron / MergeMapUDAF.java
Created July 20, 2017 06:49
Merge Map Spark User Defined Aggregation function - merge two maps of type <String, Long> to one Map.
package com.tomron;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.expressions.MutableAggregationBuffer;
import org.apache.spark.sql.expressions.UserDefinedAggregateFunction;
import org.apache.spark.sql.types.DataType;
import org.apache.spark.sql.types.DataTypes;
import org.apache.spark.sql.types.StructField;
import org.apache.spark.sql.types.StructType;