当前位置: 首页>>代码示例>>Python>>正文


Python NeuralNet.get_output方法代码示例

本文整理汇总了Python中neuralnet.NeuralNet.get_output方法的典型用法代码示例。如果您正苦于以下问题:Python NeuralNet.get_output方法的具体用法?Python NeuralNet.get_output怎么用?Python NeuralNet.get_output使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在neuralnet.NeuralNet的用法示例。


在下文中一共展示了NeuralNet.get_output方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from neuralnet import NeuralNet [as 别名]
# 或者: from neuralnet.NeuralNet import get_output [as 别名]
def main():
    scriptdir = os.path.dirname(os.path.realpath(__file__))
    data = scriptdir+'/../data/cwi_training/cwi_training.txt.lbl.conll'
    testdata = scriptdir+'/../data/cwi_testing/cwi_testing.gold.txt.lbl.conll'
    pickled_data = scriptdir+'/../data.pickle'
    parser = argparse.ArgumentParser()
    parser.add_argument('--threshold', '-t', type=float, help='Threshold for predicting 0/1. If not specified, the optimal threshold will first be computed as the median of all CV splits. May take a while.')
    parser.add_argument('--iterations', '-i', type=int, default=50, help='Training iterations.')
    parser.add_argument('--hidden-layers', '-l', dest='layers', required=True, type=int, nargs='+', help='List of layer sizes')
    parser.add_argument('--cv-splits', '-c', dest='splits', type=int, help='No. of crossvalidation splits. If not specified, no CV will be performed.')
    parser.add_argument('--data', '-d', default=data, help='Features and labels')
    parser.add_argument('--testdata', '-y', default=testdata,  help='Test data (not needed for crossval).')
    parser.add_argument('--verbose', '-v', dest='verbose', action='store_true', help='Print average loss at every training iteration.')
    parser.add_argument('--output', '-o', help="Output file")
    parser.add_argument('--features', '-f', dest='features', default=[], type=str, nargs='+', help='List of feature types')

    args = parser.parse_args()
    # X, y = load_pickled(args.data)
    combined_data = 'X_y_all.txt'
    cutoff = combine_data(args.data, args.testdata, combined_data)
    X, y, _ = feats_and_classify.collect_features(combined_data, True, args.features)
    X_tr = X[:cutoff]
    y_tr = y[:cutoff]
    X_te = X[cutoff:]
    y_te = y[cutoff:]
    conf = NeuralNetConfig(X=X, y=y, layers=args.layers, iterations=args.iterations, verbose=args.verbose)

    if args.splits:
        if args.threshold:
            crossval(X_tr,y_tr,args.splits, conf, t=args.threshold)
        else:
            # compute optimal threshold for each CV split
            print '### Computing optimal threshold... '
            ts = crossval(X_tr,y_tr,args.splits, conf)
            avg = np.average(ts)
            med = np.median(ts)
            print '\nThresholds for crossval splits:', ts
            print 'Mean threshold', avg
            print 'Median threshold', med
            print 'Threshold st.dev.', np.std(ts)
            # Run CV with fixed avg/median threshold
            print '\n\n### Running with avg. threshold... '
            crossval(X_tr,y_tr,args.splits, conf, t=avg)
            print '\n\n### Running with med. threshold... '
            crossval(X_tr,y_tr,args.splits, conf, t=med)
    else:
        
        nn = NN(conf)
        nn.train(X_tr,y_tr,args.iterations)
        if args.testdata:
            # X_test, y_test = load_pickled(args.testdata)
            pred = nn.get_output(X_te)
            if args.output:
                with open(args.output, 'w') as of:
                    for p in pred:
                        of.write('%f\n'%p)
            t, res = nn.test(X_te,y_te,args.threshold)
            resout = "G: %f, R: %f, A: %f, P: %f\n"%res
            sys.stderr.write('%s %f\n'%(' '.join(args.features), t))
            sys.stderr.write(resout)
开发者ID:jbingel,项目名称:cwi2016,代码行数:62,代码来源:nn-classify.py

示例2: main

# 需要导入模块: from neuralnet import NeuralNet [as 别名]
# 或者: from neuralnet.NeuralNet import get_output [as 别名]
def main():
    args = get_args()
    # f1_matrix holds for every training annotator: the list of tuples of 
    # avg/med f1_row based on avg/med threshold
    f1_matrix = []
    # holds for every training annotator: the list of tuples of avg/med threshold
    t_matrix = []
    current_label_list = []
    
    f1_final = [] # holds 4-tuples of avgs over (f1_avg_avg, f1_avg_med, f1_med_avg, f1_med_med) f.e. tr 
    t_final  = [] # holds 4-tuples of (t_avg_avg, t_avg_med, t_med_avg, t_med_med) f.e. tr

    #X_tr, _, v = feats_and_classify_py2.collect_features(args.parsed_file)
    with open('X_train.pickle', 'rb') as pf:
        X_tr = pickle.load(pf)
    with open('X_test.pickle', 'rb') as pf:
        X_te = pickle.load(pf)
    y_tr = feats_and_classify_py2.collect_labels_positive_threshold(args.all_annotations_file, 1)

    #X_out, _, _ = feats_and_classify_py2.collect_features(args.predictfile)
    # filter for targets
    #X_out = [x for x in X_out if not x.label == '?']

    conf = NeuralNetConfig(X=X_tr, y=y_tr, layers=args.layers, iterations=args.iterations, verbose=args.verbose)
    
    nn = NN(conf)
    nn.train(X_tr, y_tr)
    if args.threshold:
        preds = nn.predict_for_threshold(X_te, args.threshold)
    else:
        preds = nn.get_output(X_te) 
    with open(args.output, 'w') as outfile:
        for p in preds:
            #print(p)
            outfile.write(str(p))
            outfile.write('\n')
    sys.exit(0)
开发者ID:jbingel,项目名称:cwi2016,代码行数:39,代码来源:nn-predict.py


注:本文中的neuralnet.NeuralNet.get_output方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。