Skip to content

Instantly share code, notes, and snippets.

View messiest's full-sized avatar
👾
beep boop

Chris Messier messiest

👾
beep boop
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@messiest
messiest / bootstrap.py
Created December 20, 2017 18:34
bootstrap samples
def bootstrap(df, n, to_df=True):
"""
generate n bootstraped samples from a DataFrame
"""
assert isinstance(df, type(pd.DataFrame())),\
f"Expected pandas.DataFrame, got type: {type(df)}"
sample = {column: np.random.choice(df[column], size=int(n)) for column in df.columns} # column: bootstrap sample
if to_df: sample = pd.DataFrame.from_dict(sample) # convert to DataFrame
@messiest
messiest / model_runtime.py
Created December 20, 2017 18:40
evaluate average runtime of a model
def test_model(model, sample, k=5):
"""
get the mean time it takes to train the model over k-folds
"""
x = sample.copy() # set our predictors
y = x.pop('y') # set our response
mean_fit_time = np.mean(cross_validate(model, x, y, cv=k)['fit_time']) * 100 # get mean run time
return mean_fit_time
@messiest
messiest / runtime_evaluation.py
Last active December 20, 2017 23:48
model runtime evaluation
def evaluate_cores(model, data, n_samples, stride=1000, printer=False):
"""
evaluate multicore model training time
"""
N = [n for n in range(stride, (n_samples+stride), stride)] # the number of samples we're using, stride of 1000
cores = os.cpu_count() # get the number of cores
model_dict = {f"model_{n}": model(n_jobs=n) for n in range(1, cores+1)} # contruct model:instance pairs
@messiest
messiest / visualize_multicore.py
Last active December 20, 2017 22:36
visualize multicore
def visualize(data, save=False):
"""
plot the results
"""
y = data.copy() # get y-values
x = y.pop('N') # get x-values
plt.plot(x, y)
@messiest
messiest / gym_pull_super_mario.py
Created December 21, 2017 10:32
Installing gym-super-mario using gym-pull
import gym
import gym_pull
gym_pull.pull('github.com/ppaquette/gym-super-mario')
env = gym.make('ppaquette/SuperMarioBros-1-1-v0')
register(
id='SuperMarioBros-1-1-v0',
entry_point='gym.envs.ppaquette_gym_super_mario:MetaSuperMarioBrosEnv'
)
add_group(
id='ppaquette_gym_super_mario',
name='ppaquette_gym_super_mario',
description='super_mario'
)
# mario bros
add_task(
id='ppaquette/SuperMarioBros-1-1-v0',
group='ppaquette_gym_super_mario',
# Super Mario
register(
id='SuperMarioBros-1-1-v0',
entry_point='gym.envs.ppaquette_gym_super_mario:MetaSuperMarioBrosEnv',
)
register(
id='SuperMarioBros-1-2-v0',
entry_point='gym.envs.ppaquette_gym_super_mario:MetaSuperMarioBrosEnv',