iterate through a series of boosted_trees_classifier models

User 2591 | 4/8/2016, 11:19:03 PM

Hi

I am working on one of the Coursera ML courses w/ GLC. Instead of having separate models w/ names like model10, model50, model100, model200, I would like to create a dictionary (or other type of container) with the tree depth as the key and the model as the value so I can iterate through the model and evaluate, predict, etc. and collate the results into another iteratable container. I can shove the models into a dictionary with no protestation from python, but it's not too clear to me how I can access the function of each model individually. Any suggestions?

For example, I tried: ` models = {}

depth = [50, 100, 200, 500] num_dep = len(depth) i = 0

while i < numdep: model = gl.boostedtreesclassifier.create(traindata, validationset=None, target = target, features = features, maxiterations = depth[i], verbose=False) models[depth[i]] = model i = i+1

len(models) = 4 models

{50: Class : BoostedTreesClassifier

Schema


Number of examples : 37219 Number of classes : 2 Number of feature columns : 24 Number of unpacked features : 24

Settings


Number of trees : 50 Max tree depth : 6 Train accuracy : 0.7539 Validation accuracy : None Training time (sec) : 2.9299, 100: Class : BoostedTreesClassifier

Schema


Number of examples : 37219 Number of classes : 2 Number of feature columns : 24 Number of unpacked features : 24

Settings


Number of trees : 100 Max tree depth : 6 Train accuracy : 0.7996 Validation accuracy : None Training time (sec) : 5.6467, 200: Class : BoostedTreesClassifier

Schema


Number of examples : 37219 Number of classes : 2 Number of feature columns : 24 Number of unpacked features : 24

Settings


Number of trees : 200 Max tree depth : 6 Train accuracy : 0.8636 Validation accuracy : None Training time (sec) : 11.0989, 500: Class : BoostedTreesClassifier

Schema


Number of examples : 37219 Number of classes : 2 Number of feature columns : 24 Number of unpacked features : 24

Settings


Number of trees : 500 Max tree depth : 6 Train accuracy : 0.9618 Validation accuracy : None Training time (sec) : 29.5707} `

Comments

User 91 | 4/9/2016, 3:06:26 PM

You should be able to do

models[0].predict(data)