Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. import dill as pickle
  4. from bandits.empirical import EmpiricalWorld
  5. from bandits.armspec import ArmSpec
  6. from bandits.bandit_estimators import LinearRegression
  7. from sklearn.linear_model import Ridge
  8. N = 590
  9. p = 10
  10. armspec = ArmSpec(3)
  11. context_history = np.random.randn(N, p)
  12. context_history = pd.DataFrame(context_history)
  13. arm_history = armspec.sample(N)
  14.  
  15. all_rewards = pd.DataFrame({'0': context_history.iloc[:, 0],
  16. '1': 1 - context_history.iloc[:, 1],
  17. '2': context_history.iloc[:, 2]})
  18. reward_history = all_rewards.lookup(arm_history.index, arm_history['arm'])
  19.  
  20. world = EmpiricalWorld(
  21. context_history=context_history,
  22. arm_history=arm_history,
  23. reward_history=reward_history,
  24. armspec=armspec,
  25. outcome_model_estimator=Ridge(alpha=1e-5)
  26. )
  27.  
  28. FNAME = f'toronto_world_dummy_ridge_witheffect.pkl'
  29. with open(FNAME, 'wb') as fl:
  30. pickle.dump(world, fl)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement