Skip to content

Instantly share code, notes, and snippets.

@tomron
tomron / plotly_bar_chart_links.py
Created Nov 17, 2020
Add links to Plotly bar chart
View plotly_bar_chart_links.py
@tomron
tomron / plotly_back_to_back_chart.py
Last active May 31, 2021
Back to back bar chart with Plotly
View plotly_back_to_back_chart.py
import numpy as np
import matplotlib.pyplot as plt
import plotly.graph_objects as go
women_pop = np.array([5., 30., 45., 22.])
men_pop = np.array( [5., 25., 50., 20.])
y = list(range(len(women_pop)))
fig = go.Figure(data=[
go.Bar(y=y, x=women_pop, orientation='h', name="women", base=0),
@tomron
tomron / seasonal_decompose_plotly.py
Last active Nov 20, 2020
A nicer seasonal decompose chart using plotly.
View seasonal_decompose_plotly.py
from statsmodels.tsa.seasonal import seasonal_decompose
import plotly.tools as tls
def plotSeasonalDecompose(
x,
model='additive',
filt=None,
period=None,
two_sided=True,
extrapolate_trend=0,
View networkx_post.py
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 Apr 30, 2019
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])`
View sprt.py
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 Apr 30, 2019
Sequential probability ratio test
View sprt.py
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 Aug 6, 2018
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
View welchtest.py
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()
View welchtest.py
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 Jul 20, 2017
Merge Map Spark User Defined Aggregation function - merge two maps of type <String, Long> to one Map.
View MergeMapUDAF.java
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 Jul 20, 2017
Merge Map Spark User Defined Aggregation function - merge two maps of type <String, Long> to one Map.
View MergeMapUDAF.java
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;