learn/optimize_hyperparameters.py
def main():
    """
    For a training set of nuclide measurements (features) and reactor
    parameters (labels), this script optimizes the hyperparameters of three
    chosen algorithms given a training set fraction and number of
    cross-validation folds. The results are printed to text files. 
    
    """

    args = parse_args(sys.argv[1:])
    
    CV = args.cv
    tset_frac = args.tset_frac

    iters = 10
    jobs = 5
    c = 50000
    
    # get data set
    trainset = args.train_db
    trainXY = pd.read_pickle(trainset)
    #trainXY.reset_index(inplace=True, drop=True)
    if tset_frac < 1.0:
        trainXY = trainXY.sample(frac=tset_frac)
    trainX, rY, cY, eY, bY = splitXY(trainXY)
    trainX = scale(trainX)
    
    # define search breadth
    #knn_grid = {'n_neighbors': np.linspace(1, 21, iters).astype(int)}
    #dtr_grid = {"max_depth": np.linspace(20, 80, iters).astype(int),
    #            "max_features": np.linspace(5, len(trainXY.columns)-8, iters).astype(int)}
    svr_grid = {'C': np.logspace(0, 6, iters), 'gamma': np.logspace(-7, 1, iters)} 
    
    #2nd round of opt:
    knn_grid = {'n_neighbors': np.array([1, 2, 3, 4, 5, 6, 7])}
    dtr_grid = {"max_depth": np.linspace(40, 80, 30).astype(int)}

    score = 'neg_mean_absolute_error'
    kfold = KFold(n_splits=CV, shuffle=True)
    trainY = pd.Series()
    if args.rxtr_param == 'cooling':
        trainY = cY
    elif args.rxtr_param == 'burnup':
        trainY = bY
    elif args.rxtr_param == 'enrichment': 
        trainY = eY
    else:
        trainY = rY
        score = 'accuracy'
        kfold = StratifiedKFold(n_splits=CV, shuffle=True)
    
    # save results
    outfile = args.rxtr_param + '_' + args.alg + '_' + args.db_desc + '_hyperparameters.txt'
    with open(outfile, 'a') as of:
        of.write(args.alg + ' hyperparameter optimization for ' + args.rxtr_param + ', ' + args.db_desc  + ':')
    
    arg_dict = {'score' : score, 'jobs' : jobs, 'kfold' : kfold,
                'pred' : args.rxtr_param, 'file' : outfile, 'c' : c}

    if args.alg == 'knn':
        opt_knn(knn_grid, trainX, trainY, arg_dict)
    elif args.alg == 'dtree':
        opt_dtr(dtr_grid, trainX, trainY, arg_dict)
    else:
        opt_svm(svr_grid, trainX, trainY, arg_dict)
    
    return

    For a training set of nuclide measurements (features) and reactor
    parameters (labels), this script optimizes the hyperparameters of three
    chosen algorithms given a training set fraction and number of
    cross-validation folds. The results are printed to text files. 
    
    
For a training set of nuclide measurements (features) and reactor
parameters (labels), this script optimizes the hyperparameters of three
chosen algorithms given a training set fraction and number of
cross-validation folds. The results are printed to text files.
For a training set of nuclide measurements ( features ) and reactor parameters ( labels ) this script optimizes the hyperparameters of three chosen algorithms given a training set fraction and number of cross - validation folds . The results are printed to text files .
def main():
    args = parse_args(sys.argv[1:])
    CV = args.cv
    tset_frac = args.tset_frac
    iters = 10
    jobs = 5
    c = 50000
    trainset = args.train_db
    trainXY = pd.read_pickle(trainset)
    if tset_frac < 1.0:
        trainXY = trainXY.sample(frac=tset_frac)
    trainX, rY, cY, eY, bY = splitXY(trainXY)
    trainX = scale(trainX)
    svr_grid = {'C': np.logspace(0, 6, iters), 'gamma': np.logspace(-7, 1, iters)} 
    knn_grid = {'n_neighbors': np.array([1, 2, 3, 4, 5, 6, 7])}
    dtr_grid = {"max_depth": np.linspace(40, 80, 30).astype(int)}
    score = 'neg_mean_absolute_error'
    kfold = KFold(n_splits=CV, shuffle=True)
    trainY = pd.Series()
    if args.rxtr_param == 'cooling':
        trainY = cY
    elif args.rxtr_param == 'burnup':
        trainY = bY
    elif args.rxtr_param == 'enrichment': 
        trainY = eY
    else:
        trainY = rY
        score = 'accuracy'
        kfold = StratifiedKFold(n_splits=CV, shuffle=True)
    outfile = args.rxtr_param + '_' + args.alg + '_' + args.db_desc + '_hyperparameters.txt'
    with open(outfile, 'a') as of:
        of.write(args.alg + ' hyperparameter optimization for ' + args.rxtr_param + ', ' + args.db_desc  + ':')
    arg_dict = {'score' : score, 'jobs' : jobs, 'kfold' : kfold,
                'pred' : args.rxtr_param, 'file' : outfile, 'c' : c}
    if args.alg == 'knn':
        opt_knn(knn_grid, trainX, trainY, arg_dict)
    elif args.alg == 'dtree':
        opt_dtr(dtr_grid, trainX, trainY, arg_dict)
    else:
        opt_svm(svr_grid, trainX, trainY, arg_dict)
    return
def main ( ) : args = parse_args ( sys . argv [ 1 : ] ) CV = args . cv tset_frac = args . tset_frac iters = 10 jobs = 5 c = 50000 trainset = args . train_db trainXY = pd . read_pickle ( trainset ) if tset_frac < 1.0 : trainXY = trainXY . sample ( frac = tset_frac ) trainX , rY , cY , eY , bY = splitXY ( trainXY ) trainX = scale ( trainX ) svr_grid = { 'C' : np . logspace ( 0 , 6 , iters ) , 'gamma' : np . logspace ( - 7 , 1 , iters ) } knn_grid = { 'n_neighbors' : np . array ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ) } dtr_grid = { "max_depth" : np . linspace ( 40 , 80 , 30 ) . astype ( int ) } score = 'neg_mean_absolute_error' kfold = KFold ( n_splits = CV , shuffle = True ) trainY = pd . Series ( ) if args . rxtr_param == 'cooling' : trainY = cY elif args . rxtr_param == 'burnup' : trainY = bY elif args . rxtr_param == 'enrichment' : trainY = eY else : trainY = rY score = 'accuracy' kfold = StratifiedKFold ( n_splits = CV , shuffle = True ) outfile = args . rxtr_param + '_' + args . alg + '_' + args . db_desc + '_hyperparameters.txt' with open ( outfile , 'a' ) as of : of . write ( args . alg + ' hyperparameter optimization for ' + args . rxtr_param + ', ' + args . db_desc + ':' ) arg_dict = { 'score' : score , 'jobs' : jobs , 'kfold' : kfold , 'pred' : args . rxtr_param , 'file' : outfile , 'c' : c } if args . alg == 'knn' : opt_knn ( knn_grid , trainX , trainY , arg_dict ) elif args . alg == 'dtree' : opt_dtr ( dtr_grid , trainX , trainY , arg_dict ) else : opt_svm ( svr_grid , trainX , trainY , arg_dict ) return
For a training set of nuclide measurements (features) and reactor
parameters (labels), this script optimizes the hyperparameters of three
chosen algorithms given a training set fraction and number of
cross-validation folds.
For a training set of nuclide measurements ( features ) and reactor parameters ( labels ) this script optimizes the hyperparameters of three chosen algorithms given a training set fraction and number of cross - validation folds .
"""
    For a training set of nuclide measurements (features) and reactor
    parameters (labels), this script optimizes the hyperparameters of three
    chosen algorithms given a training set fraction and number of
    cross-validation folds. The results are printed to text files. 
    
    """ # get data set #trainXY.reset_index(inplace=True, drop=True) # define search breadth #knn_grid = {'n_neighbors': np.linspace(1, 21, iters).astype(int)} #dtr_grid = {"max_depth": np.linspace(20, 80, iters).astype(int), #            "max_features": np.linspace(5, len(trainXY.columns)-8, iters).astype(int)} #2nd round of opt: # save results