learn/optimize_hyperparameters.py
def opt_dtr(grid, trainX, trainY, arg):
    """
    Optimizes the decision tree algorithm, prints the top score and 
    hyperparameters in a text file.

    Parameters
    ----------
    grid : a dict of hyperparameters and range of them to optimize over
    trainX : feature set of nuclide measurements
    trainY : parameter being predicted (e.g., burnup, cooling time)
    arg : a dict of various parameters needed for GridSearchCV and output file

    """
    dtr_init = DecisionTreeRegressor()
    if arg['pred'] == 'reactor': 
        dtr_init = DecisionTreeClassifier(class_weight='balanced')
    dtr_opt = GridSearchCV(estimator=dtr_init, param_grid=grid,
                           scoring=arg['score'], n_jobs=arg['jobs'], 
                           cv=arg['kfold'], return_train_score=True)
    dtr_opt.fit(trainX, trainY)

    tmpl = Template(
'''
score: $score
max_depth: $d
''')
#max_features: $f
    txt = tmpl.substitute(score = dtr_opt.best_score_,
                          d = dtr_opt.best_params_['max_depth'])#,
                          #f = dtr_opt.best_params_['max_features'])
    with open(arg['file'], 'a') as f:
        f.write(txt)
    return

    Optimizes the decision tree algorithm, prints the top score and 
    hyperparameters in a text file.

    Parameters
    ----------
    grid : a dict of hyperparameters and range of them to optimize over
    trainX : feature set of nuclide measurements
    trainY : parameter being predicted (e.g., burnup, cooling time)
    arg : a dict of various parameters needed for GridSearchCV and output file

    
Optimizes the decision tree algorithm, prints the top score and
hyperparameters in a text file.

Parameters

grid : a dict of hyperparameters and range of them to optimize over
trainX : feature set of nuclide measurements
trainY : parameter being predicted
arg : a dict of various parameters needed for GridSearchCV and output file
Optimizes the decision tree algorithm prints the top score and hyperparameters in a text file . Parameters grid : a dict of hyperparameters and range of them to optimize over trainX : feature set of nuclide measurements trainY : parameter being predicted arg : a dict of various parameters needed for GridSearchCV and output file
def opt_dtr(grid, trainX, trainY, arg):
    dtr_init = DecisionTreeRegressor()
    if arg['pred'] == 'reactor': 
        dtr_init = DecisionTreeClassifier(class_weight='balanced')
    dtr_opt = GridSearchCV(estimator=dtr_init, param_grid=grid,
                           scoring=arg['score'], n_jobs=arg['jobs'], 
                           cv=arg['kfold'], return_train_score=True)
    dtr_opt.fit(trainX, trainY)
    tmpl = Template(
'''
score: $score
max_depth: $d
''')
    txt = tmpl.substitute(score = dtr_opt.best_score_,
                          d = dtr_opt.best_params_['max_depth'])
    with open(arg['file'], 'a') as f:
        f.write(txt)
    return
def opt_dtr ( grid , trainX , trainY , arg ) : dtr_init = DecisionTreeRegressor ( ) if arg [ 'pred' ] == 'reactor' : dtr_init = DecisionTreeClassifier ( class_weight = 'balanced' ) dtr_opt = GridSearchCV ( estimator = dtr_init , param_grid = grid , scoring = arg [ 'score' ] , n_jobs = arg [ 'jobs' ] , cv = arg [ 'kfold' ] , return_train_score = True ) dtr_opt . fit ( trainX , trainY ) tmpl = Template ( '''
score: $score
max_depth: $d
''' ) txt = tmpl . substitute ( score = dtr_opt . best_score_ , d = dtr_opt . best_params_ [ 'max_depth' ] ) with open ( arg [ 'file' ] , 'a' ) as f : f . write ( txt ) return
Optimizes the decision tree algorithm, prints the top score and
hyperparameters in a text file.
Optimizes the decision tree algorithm prints the top score and hyperparameters in a text file .
"""
    Optimizes the decision tree algorithm, prints the top score and 
    hyperparameters in a text file.

    Parameters
    ----------
    grid : a dict of hyperparameters and range of them to optimize over
    trainX : feature set of nuclide measurements
    trainY : parameter being predicted (e.g., burnup, cooling time)
    arg : a dict of various parameters needed for GridSearchCV and output file

    """ #max_features: $f #, #f = dtr_opt.best_params_['max_features'])
grid
trainX
trainY
arg