Skip to content

Instantly share code, notes, and snippets.

def BayesianMMM(splits="W"):
if splits == "Q":
time_series = pd.PeriodIndex(dates, freq='Q').astype(str).str[-1].astype(int).values
elif splits == "H":
time_series = pd.PeriodIndex(dates, freq='Q').astype(str).str[-1].map({'1':1, '2':1, '3':2, '4':2}).values
elif splits == "YoY":
time_series = np.array([1]*52 + [2]*52)
else:
time_series = np.arange(104)
@egemenzeytinci
egemenzeytinci / feature_importance.py
Created December 15, 2019 09:58
Feature importances in python
from rfpimp import permutation_importances
from sklearn.base import clone
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import r2_score
from sklearn.model_selection import train_test_split
import pandas as pd
def imp_df(column_names, importances):
data = {
from scipy.stats import beta
import numpy as np
from calc_prob import calc_prob_between
#This is the known data: imporessions and conversions for the Control and Test set
imps_ctrl,convs_ctrl=16500, 30
imps_test, convs_test=17000, 50
#here we create the Beta functions for the two sets
a_C, b_C = convs_ctrl+1, imps_ctrl-convs_ctrl+1
@mnguyenngo
mnguyenngo / zscore.py
Last active June 14, 2024 14:47
Code to calculate and plot the z-score
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as scs
def z_val(sig_level=0.05, two_tailed=True):
"""Returns the z value for a given significance level"""
z_dist = scs.norm()
if two_tailed:
sig_level = sig_level/2
area = 1 - sig_level