Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cPickle as pickle
- import random
- import hashlib
- def ParamsID(a):
- '''
- Using hash function to build an unique identifier for each dictionary
- '''
- ID = 1
- for x in a.keys():
- ID = ID + int(hashlib.sha256(str(a[x]).encode('utf-8')).hexdigest(), 16)
- ID = ID + int(hashlib.sha256(x.encode('utf-8')).hexdigest(), 16)
- return (ID % 10**10)
- def getRandomParams():
- '''
- Returns a dictionary containing all the parameters for a BDT classifier
- '''
- p_lr = [1.0,0.1,0.01,0.001,0.0001]
- p_n = [25,50,100,150,200,250,300,400,500]
- p_max = [2,3,4,5,6,3]
- p_leaves = [1,10,50,100,0.001,0.0001,1,1]
- mydic = {}
- mydic['lr'] = random.choice(p_lr)
- mydic['n'] = random.choice(p_n)
- mydic['max'] = random.choice(p_max)
- mydic['leaves'] = random.choice(p_leaves)
- return mydic
- def _run():
- params = getRandomParams()
- ID = ParamsID(params) # Get an unique ID associated to the parameters
- with open('models/params_' + str(ID) + '.pick','w') as f: # Save the parameters into a file determined by unique ID
- pickle.dump(params,f)
- results = run_algorithm(params)
- save_results(params,ID)
- if __name__ == '__main__':
- for x in range(5): # Runs the algorithm on 5 random sets of parameters
- _run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement