This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
from sklearn.ensemble import RandomForestRegressor | |
from ds_projects.lift_model.erupt import get_erupts_curves_aupc | |
def get_simple_uplift_data(num_obs): | |
"""Creates sample uplift dataset with 3 variables. | |
First two variables are of form y_i = x_i*t + e for two responses | |
Thrid response is just noise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn.linear_model import LinearRegression | |
from sklearn.ensemble import RandomForestRegressor | |
num_obs = 1000 | |
t = np.random.binomial(1, .5, num_obs) | |
x = np.random.binomial(1, .5, num_obs) | |
y = 10 + 2*t*x - t + np.random.normal(0, .1, num_obs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
import random | |
def weighted_avg_and_std(values, weights): | |
"""computes weighted averages and stdevs | |
Args: | |
values (np.array): variable of interest | |
weight (np.array): weight to assign each observation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
from keras import backend as K | |
from keras.layers import Input, Dense, Dropout | |
from keras.models import Model | |
from keras.wrappers.scikit_learn import KerasRegressor | |
from sklearn.metrics import make_scorer | |
from sklearn.model_selection import GridSearchCV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(genlasso) | |
d <- data.frame(x = sample(-seq(-20,20,2), 1e5, replace = TRUE)) %>% | |
mutate(event_rate = abs(round((x)/2)/10), | |
y = rbinom(n(), 1, event_rate), | |
x_fctr = as.factor(x)) | |
y <- d$y |