old_scripts/manual_preds.py
def manual_train_and_predict(train, test):
    """
    Given training and testing data, this script runs some ML algorithms
    (currently, this is nearest neighbors with 2 distance metrics and ridge
    regression) for each prediction category: reactor type, enrichment, and
    burnup

    Parameters 
    ---------- 
    
    train : group of dataframes that include training instances and the labels
    test : group of dataframes that has the testing instances and the labels

    Returns
    -------
    burnup : tuple of MAPE for training, testing, and cross validation errors
             for all three algorithms

    """

    k = 1
    a = 1
    g = 0.001
    c = 1000

    mape_cols = ['TrainPerScore', 'TestPerScore', 'CVPerScore']
    rmse_cols = ['TrainNegRMSErr', 'TestNegRMSErr', 'CVNegRMSErr']
    mae_cols = ['TrainNegMAErr', 'TestNegMAErr', 'CVNegMAErr']
    
    trainX = scale(train.nuc_concs)
    trainY = train.burnup
    testX = test.nuc_concs
    testY = test.burnup
    
    # no diagnostics: burnup prediction results only
    #for alg_type in ('nn', 'rr', 'svr'):
    #    if alg_type == 'nn':
    #        alg = KNeighborsRegressor(n_neighbors=k) 
    #    elif alg_type == 'rr':
    #        alg = Ridge(alpha=a)
    #    else:
    #        alg = SVR(gamma=g, C=c)
    #    mape, rmse, mae = burnup_predict(trainX, trainY, testX, testY, alg)
    #add print statement here
    
    #########################
    # Manual Learning Curves#
    #########################
   # m_percent = np.linspace(0.15, 1.0, 20)
   # for alg_type in ('nn', 'rr', 'svr'):
   #     map_err = []
   #     rms_err = []
   #     ma_err = []
   #     if alg_type == 'nn':
   #         alg = KNeighborsRegressor(n_neighbors=k) 
   #     elif alg_type == 'rr':
   #         alg = Ridge(alpha=a)
   #     else:
   #         alg = SVR(gamma=g, C=c)
   #     for m in m_percent:
   #         # reduce training set size
   #         trainX, trainY = m_reduc(m, train)
   #         mape, rmse, mae = burnup_predict(trainX, trainY, testX, testY, alg)
   #         map_err.append(mape)
   #         rms_err.append(rmse)
   #         ma_err.append(mae)
   #     mape = pd.DataFrame(map_err, columns=mape_cols, index=m_percent)
   #     rmse = pd.DataFrame(rms_err, columns=rmse_cols, index=m_percent)
   #     mae = pd.DataFrame(ma_err, columns=mae_cols, index=m_percent)
   #     errors = pd.concat([mape, rmse, mae], axis=1)
   #     errors.to_csv(alg_type + '_learn_manual.csv')
    
    
    ############################
    # Manual Validation Curves #
    ############################
    k_list = np.linspace(1, 39, 20)
    alpha_list = np.logspace(-7, 3, 20)
    gamma_list = np.linspace(0.0005, 0.09, 20)
    c_list = np.linspace(0.01, 100000, 20)
    
    for alg_type in ('svr_c',):#('nn', 'rr', 'svr_c', 'svr_g'):
        map_err = []
        rms_err = []
        ma_err = []
        idx = []
        if alg_type == 'svr_c':
            idx = c_list
            for c in c_list:
                alg = SVR(C=c, gamma=g)
                pt, ms, ma = burnup_predict(trainX, trainY, testX, testY, alg)
                map_err.append(pt)
                rms_err.append(ms)
                ma_err.append(ma)
        elif alg_type == 'svr_g':
            idx = gamma_list
            c = 1000
            for g in gamma_list:
                alg = SVR(C=c, gamma=g)
                pt, ms, ma = burnup_predict(trainX, trainY, testX, testY, alg)
                map_err.append(pt)
                rms_err.append(ms)
                ma_err.append(ma)
        elif alg_type == 'nn':
            idx = k_list
            for k in k_list:
                alg = KNeighborsRegressor(n_neighbors=k)
                pt, ms, ma = burnup_predict(trainX, trainY, testX, testY, alg)
                map_err.append(pt)
                rms_err.append(ms)
                ma_err.append(ma)
        elif alg_type == 'rr':
            idx = alpha_list
            for a in alpha_list:
                alg = Ridge(alpha=a)
                pt, ms, ma = burnup_predict(trainX, trainY, testX, testY, alg)
                map_err.append(pt)
                rms_err.append(ms)
                ma_err.append(ma)
        else:
            print('Derp.\n')
        mape = pd.DataFrame(map_err, columns=mape_cols, index=idx)
        rmse = pd.DataFrame(rms_err, columns=rmse_cols, index=idx)
        mae = pd.DataFrame(ma_err, columns=mae_cols, index=idx)
        errors = pd.concat([mape, rmse, mae], axis=1)
        errors.to_csv(alg_type + '_valid_manual.csv')

    return

    Given training and testing data, this script runs some ML algorithms
    (currently, this is nearest neighbors with 2 distance metrics and ridge
    regression) for each prediction category: reactor type, enrichment, and
    burnup

    Parameters 
    ---------- 
    
    train : group of dataframes that include training instances and the labels
    test : group of dataframes that has the testing instances and the labels

    Returns
    -------
    burnup : tuple of MAPE for training, testing, and cross validation errors
             for all three algorithms

    
Given training and testing data, this script runs some ML algorithms
(currently, this is nearest neighbors with 2 distance metrics and ridge
regression) for each prediction category: reactor type, enrichment, and
burnup
Given training and testing data this script runs some ML algorithms ( currently this is nearest neighbors with 2 distance metrics and ridge regression ) for each prediction category : reactor type enrichment and burnup
def manual_train_and_predict(train, test):
    k = 1
    a = 1
    g = 0.001
    c = 1000
    mape_cols = ['TrainPerScore', 'TestPerScore', 'CVPerScore']
    rmse_cols = ['TrainNegRMSErr', 'TestNegRMSErr', 'CVNegRMSErr']
    mae_cols = ['TrainNegMAErr', 'TestNegMAErr', 'CVNegMAErr']
    trainX = scale(train.nuc_concs)
    trainY = train.burnup
    testX = test.nuc_concs
    testY = test.burnup
    ###
    ###
    k_list = np.linspace(1, 39, 20)
    alpha_list = np.logspace(-7, 3, 20)
    gamma_list = np.linspace(0.0005, 0.09, 20)
    c_list = np.linspace(0.01, 100000, 20)
    for alg_type in ('svr_c',):
        map_err = []
        rms_err = []
        ma_err = []
        idx = []
        if alg_type == 'svr_c':
            idx = c_list
            for c in c_list:
                alg = SVR(C=c, gamma=g)
                pt, ms, ma = burnup_predict(trainX, trainY, testX, testY, alg)
                map_err.append(pt)
                rms_err.append(ms)
                ma_err.append(ma)
        elif alg_type == 'svr_g':
            idx = gamma_list
            c = 1000
            for g in gamma_list:
                alg = SVR(C=c, gamma=g)
                pt, ms, ma = burnup_predict(trainX, trainY, testX, testY, alg)
                map_err.append(pt)
                rms_err.append(ms)
                ma_err.append(ma)
        elif alg_type == 'nn':
            idx = k_list
            for k in k_list:
                alg = KNeighborsRegressor(n_neighbors=k)
                pt, ms, ma = burnup_predict(trainX, trainY, testX, testY, alg)
                map_err.append(pt)
                rms_err.append(ms)
                ma_err.append(ma)
        elif alg_type == 'rr':
            idx = alpha_list
            for a in alpha_list:
                alg = Ridge(alpha=a)
                pt, ms, ma = burnup_predict(trainX, trainY, testX, testY, alg)
                map_err.append(pt)
                rms_err.append(ms)
                ma_err.append(ma)
        else:
            print('Derp.\n')
        mape = pd.DataFrame(map_err, columns=mape_cols, index=idx)
        rmse = pd.DataFrame(rms_err, columns=rmse_cols, index=idx)
        mae = pd.DataFrame(ma_err, columns=mae_cols, index=idx)
        errors = pd.concat([mape, rmse, mae], axis=1)
        errors.to_csv(alg_type + '_valid_manual.csv')
    return
def manual_train_and_predict ( train , test ) : k = 1 a = 1 g = 0.001 c = 1000 mape_cols = [ 'TrainPerScore' , 'TestPerScore' , 'CVPerScore' ] rmse_cols = [ 'TrainNegRMSErr' , 'TestNegRMSErr' , 'CVNegRMSErr' ] mae_cols = [ 'TrainNegMAErr' , 'TestNegMAErr' , 'CVNegMAErr' ] trainX = scale ( train . nuc_concs ) trainY = train . burnup testX = test . nuc_concs testY = test . burnup k_list = np . linspace ( 1 , 39 , 20 ) alpha_list = np . logspace ( - 7 , 3 , 20 ) gamma_list = np . linspace ( 0.0005 , 0.09 , 20 ) c_list = np . linspace ( 0.01 , 100000 , 20 ) for alg_type in ( 'svr_c' , ) : map_err = [ ] rms_err = [ ] ma_err = [ ] idx = [ ] if alg_type == 'svr_c' : idx = c_list for c in c_list : alg = SVR ( C = c , gamma = g ) pt , ms , ma = burnup_predict ( trainX , trainY , testX , testY , alg ) map_err . append ( pt ) rms_err . append ( ms ) ma_err . append ( ma ) elif alg_type == 'svr_g' : idx = gamma_list c = 1000 for g in gamma_list : alg = SVR ( C = c , gamma = g ) pt , ms , ma = burnup_predict ( trainX , trainY , testX , testY , alg ) map_err . append ( pt ) rms_err . append ( ms ) ma_err . append ( ma ) elif alg_type == 'nn' : idx = k_list for k in k_list : alg = KNeighborsRegressor ( n_neighbors = k ) pt , ms , ma = burnup_predict ( trainX , trainY , testX , testY , alg ) map_err . append ( pt ) rms_err . append ( ms ) ma_err . append ( ma ) elif alg_type == 'rr' : idx = alpha_list for a in alpha_list : alg = Ridge ( alpha = a ) pt , ms , ma = burnup_predict ( trainX , trainY , testX , testY , alg ) map_err . append ( pt ) rms_err . append ( ms ) ma_err . append ( ma ) else : print ( 'Derp.\n' ) mape = pd . DataFrame ( map_err , columns = mape_cols , index = idx ) rmse = pd . DataFrame ( rms_err , columns = rmse_cols , index = idx ) mae = pd . DataFrame ( ma_err , columns = mae_cols , index = idx ) errors = pd . concat ( [ mape , rmse , mae ] , axis = 1 ) errors . to_csv ( alg_type + '_valid_manual.csv' ) return
Given training and testing data, this script runs some ML algorithms
(currently, this is nearest neighbors with 2 distance metrics and ridge
regression) for each prediction category: reactor type, enrichment, and
burnup
Given training and testing data this script runs some ML algorithms ( currently this is nearest neighbors with 2 distance metrics and ridge regression ) for each prediction category : reactor type enrichment and burnup
"""
    Given training and testing data, this script runs some ML algorithms
    (currently, this is nearest neighbors with 2 distance metrics and ridge
    regression) for each prediction category: reactor type, enrichment, and
    burnup

    Parameters 
    ---------- 
    
    train : group of dataframes that include training instances and the labels
    test : group of dataframes that has the testing instances and the labels

    Returns
    -------
    burnup : tuple of MAPE for training, testing, and cross validation errors
             for all three algorithms

    """ # no diagnostics: burnup prediction results only #for alg_type in ('nn', 'rr', 'svr'): #    if alg_type == 'nn': #        alg = KNeighborsRegressor(n_neighbors=k)  #    elif alg_type == 'rr': #        alg = Ridge(alpha=a) #    else: #        alg = SVR(gamma=g, C=c) #    mape, rmse, mae = burnup_predict(trainX, trainY, testX, testY, alg) #add print statement here ######################### # Manual Learning Curves# ######################### # m_percent = np.linspace(0.15, 1.0, 20) # for alg_type in ('nn', 'rr', 'svr'): #     map_err = [] #     rms_err = [] #     ma_err = [] #     if alg_type == 'nn': #         alg = KNeighborsRegressor(n_neighbors=k)  #     elif alg_type == 'rr': #         alg = Ridge(alpha=a) #     else: #         alg = SVR(gamma=g, C=c) #     for m in m_percent: #         # reduce training set size #         trainX, trainY = m_reduc(m, train) #         mape, rmse, mae = burnup_predict(trainX, trainY, testX, testY, alg) #         map_err.append(mape) #         rms_err.append(rmse) #         ma_err.append(mae) #     mape = pd.DataFrame(map_err, columns=mape_cols, index=m_percent) #     rmse = pd.DataFrame(rms_err, columns=rmse_cols, index=m_percent) #     mae = pd.DataFrame(ma_err, columns=mae_cols, index=m_percent) #     errors = pd.concat([mape, rmse, mae], axis=1) #     errors.to_csv(alg_type + '_learn_manual.csv') ############################ # Manual Validation Curves # ############################ #('nn', 'rr', 'svr_c', 'svr_g'):
train
None
test
None
Returns
None
burnup
for all three algorithms
for all three algorithms