import slack_news_bot import common_params import datetime import util_funcs from mab import algorithm as bd from mab import arm from mab import scorer as sc import time import pickle is_post_per_subject = False is_update_db = True param = common_params.CommonParams() bot = slack_news_bot.SlackNewsBot(param, is_update_db) df = bot.df num_arms = param.num_news path = 'log/mab.log' if util_funcs.check_file(path) is False: algorithm = bd.EpsilonGreedyAlgorithm(num_arms, 0.1) trials = 0 with open(path, 'wb') as f: pickle.dump(algorithm, f) pickle.dump(trials, f) print("MAB started") else: with open(path, 'rb') as f: algorithm = pickle.load(f) trials = pickle.load(f) print("MAB object loaded")
from mab import algorithm as bd from mab import arm from mab import scorer as sc import time import slack_news_bot as newsbot import common_params from sklearn import preprocessing bot = newsbot.SlackNewsBot(common_params.CommonParams()) msg = bot.post_message(True) df = bot.df df_encoding = df[['subject_idx', 'is_emphasis', 'num_omitted', 'news_creator']] le = preprocessing.LabelEncoder() df_encoding = df_encoding.apply(le.fit_transform) print(df_encoding) # 1. INSTANTIATE enc = preprocessing.OneHotEncoder() # 2. FIT enc.fit(df_encoding) # 3. Transform onehotlabels = enc.transform(df_encoding).toarray() print(onehotlabels.shape) #print(onehotlabels) # as you can see, you've the same number of rows 891