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


Python DictReader.remove方法代码示例

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


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

示例1: main

# 需要导入模块: from csv import DictReader [as 别名]
# 或者: from csv.DictReader import remove [as 别名]
def main(args):
    voting_methods = ['none', 'hard', 'soft']
    assert args.vote in voting_methods, "--vote must be one of 'none', 'hard', 'soft'"

    if 'small_yeast_data' in args.data_file:
        out_file_name = '../logs/small_yeast_data_log.csv'
    if 'large_yeast_data' in args.data_file:
        out_file_name = '../logs/large_yeast_data_best_results_log.csv'

    if args.classify:
        # Store column names as features, except ORF and Essential
        all_features = DictReader(open(args.train_file, 'r')).fieldnames
        all_features.remove('ORF')
        all_features.remove('Essential')

        # Cast to list to keep it all in memory
        train = list(DictReader(open(args.train_file, 'r')))
        test = list(DictReader(open(args.test_file, 'r')))

        labels = []
        for line in train:
            if line[ESSENTIAL] not in labels:
                labels.append(int(line[ESSENTIAL]))

        train_features = []
        for example in train:
            train_feat = []
            for feature in args.features:
                train_feat.append(example[feature])
            train_features.append(train_feat)
        x_train = np.array(train_features, dtype=float)
        
        test_features = []
        for example in test:
            test_feature = []
            for feature in args.features:
                test_feature.append(example[feature])
            test_features.append(test_feature)
            global orfs
            orfs.append(example[ORF])
        x_test = np.array(test_features, dtype=float)

        y_train = np.array([int(x[ESSENTIAL]) for x in train])

        y_test = np.array([int(x[ESSENTIAL]) for x in test])

        if args.scale:
            scaler = StandardScaler()
            x_train = scaler.fit_transform(x_train)
            x_test = scaler.fit_transform(x_test)

        if args.vote == 'none':
            for classifier in args.classifiers:
                model = __get_classifier_model(classifier, args)
                clf = model.fit(x_train, y_train)
                print "Using classifier " + classifier
                __print_and_log_results(clf, classifier, x_train, x_test, y_test,
                                        out_file_name, all_features, args)
        else:
            model = __get_classifier_model('none', args)
            clf = model.fit(x_train, y_train)
            print "Using classifier: vote " + args.vote + " with ", args.classifiers
            classifier = "vote-" + args.vote + "-with-classifiers_"
            classifier += "_".join(args.classifiers)
            __print_and_log_results(clf, classifier, x_train, x_test, y_test,
                                    out_file_name, all_features, args)

    elif args.cross_validate:

        # Store column names as features, except ORF and Essential
        all_features = DictReader(open(args.data_file, 'rU')).fieldnames
        all_features.remove('ORF')
        all_features.remove('Essential')
        # Cast to list to keep it all in memory
        data = list(DictReader(open(args.data_file, 'rU')))

        labels = []
        for line in data:
            labels.append(int(line[ESSENTIAL]))
        train_features = []
        for example in data:
            train_feat = []
            for feature in args.features:
                train_feat.append(example[feature])
            train_features.append(train_feat)
        x_train = np.array(train_features, dtype=float)
        X_train, X_test, y_train, y_test = cross_validation.train_test_split (x_train, labels, test_size=0.1)

        if args.scale:
            scaler = StandardScaler().fit(X_train)
            X_train = scaler.transform(X_train)
            X_test = scaler.transform(X_test)
        if args.vote == 'none':
            for classifier in args.classifiers:
                model = __get_classifier_model(classifier, args)
                clf = model.fit(X_train, y_train)
                print "Using classifier " + classifier
                __print_and_log_results(clf, classifier, X_train, X_test, y_test,
                                        out_file_name, all_features, args)
        else:
#.........这里部分代码省略.........
开发者ID:ranikay,项目名称:CSCI5622-CourseProject,代码行数:103,代码来源:classify.py


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