コード例 #1
0
ファイル: driver.py プロジェクト: newbie-gk/WhaleRedux2
def main(maxFeatures=30, maxDepth=8):

    print "maxFeatures:", maxFeatures
    print "maxDepth   :", maxDepth

    baseDir = globalConst.BASE_DIR

    params = {
        "max_depth": maxDepth,
        "subsample": 0.5,
        "verbose": 2,
        "random_state": 0,
        "min_samples_split": 20,
        "min_samples_leaf": 20,
        "max_features": maxFeatures,
        "n_estimators": 500,
        "learning_rate": 0.05,
    }
    #'n_estimators': 12000, 'learning_rate': 0.002}
    clf = GradientBoostingClassifier(**params)

    # NOTE: first pass, no orderFile; 2nd pass, use orderfiles
    test = Classify(
        trainFile=baseDir + "workspace/trainMetrics.csv", orderFile=useIfExists(baseDir + "/moby/corr32.csv")
    )

    test.validate(clf=clf, nFolds=2, featureImportance=True, outFile=baseDir + "moby/trainPredictions.csv")

    test.testAndOutput(
        clf=clf,
        testFile=baseDir + "workspace/testMetrics.csv",
        orderFile=useIfExists(baseDir + "/moby/testCorr32.csv"),
        outfile=baseDir + "moby/testPredictions.sub",
    )  # NOTE .sub, not .csv
コード例 #2
0
 def cl(self):
     self.cl = Classify()
     a = self.cl.classify_r1()
     self.textEdit_2.setText(a + ' >>')
     b = self.cl.classify_r2(a)
     self.textEdit_2.append(b)
     self.textEdit_3.setText("Tweet Classfied")
コード例 #3
0
def main():
    path = "data/yellow-small.csv"
    dry_run = False

    # parse tags
    if len(sys.argv) == 2:
        if sys.argv[1] == DRY_RUN:
            dry_run = True
        else:
            path = sys.argv[1]
    if len(sys.argv) == 3 and sys.argv[2] == DRY_RUN:
        dry_run = True
        path = sys.argv[1]

    # parse input
    im = Importer(path)
    im.parse_data()

    # build tree
    tree = DecisionTree(im)
    tree.build_tree(THRESH)
    print(tree.tree_to_json())

    # classify data
    classify = Classify(path, tree.tree)
    classify.check_data(dry_run)
コード例 #4
0
def main(model='production.pkl'):
    # setup
    classify = Classify(ARTIFACT_PATH, model)

    ## CONTROL LOOPS ##
    while not rover.isDeadZone():
        if not rover.isOverride():
            # run this guy at 1Hz
            start = timer()

            # classify camera images
            camera_imgs = rover.getImgs()
            camera_preds = []
            # may have to convert images here or change classify class
            for img in camera_imgs:
                camera_preds.append(classify.predict(img))

            # confirm we are onlyhot running at 1Hz
            # and check if we are running over
            if timer() - start > 1:
                print('--BELOW 1HZ')
            print(timer() - start)
            while timer() - start < 1:
                pass
    while rover.isDeadZone():
        # run this guy at 1Hz
        start = timer()

        # do stuff here

        signal = rover.getSignalStrength()

        while timer() - start < 1:
            pass
コード例 #5
0
ファイル: driver.py プロジェクト: wuzhongdehua/moby
def main():
	baseDir = '/Users/nkridler/Desktop/whale/'

	params = {'max_depth':8, 'subsample':0.5, 'verbose':2, 'random_state':0
		'min_samples_split':20, 'min_samples_leaf':20, 'max_features':30,
		'n_estimators': 500, 'learning_rate': 0.05}
		#'n_estimators': 12000, 'learning_rate': 0.002}
	clf = GradientBoostingClassifier(**params)	
	test = Classify(baseDir+'workspace/trainMetrics.csv')
	test.validate(clf,nFolds=2,featureImportance=True)
コード例 #6
0
def main():
	baseDir = '/home/nick/whale/'
	params = {'max_depth':8, 'subsample':0.5, 'verbose':2, 'random_state':0,
			'min_samples_split':20, 'min_samples_leaf':20, 'max_features':30,
			'n_estimators': 12000, 'learning_rate': 0.002}
	clf = GradientBoostingClassifier(**params)

	# Generate a submission with corr32 and all metrics
	test = Classify(trainFile=baseDir+'workspace/trainMetrics.csv',
					orderFile=baseDir+'moby/corr32.csv')
	test.testAndOutput(clf=clf,
		testFile=baseDir+'workspace/testMetrics.csv',
		orderFile=baseDir+'moby/testCorr32.csv',
		outfile='submit32.sub')

	# Generate a submission with corr64 and no time metrics
	noTime = np.array(range(150) + range(385,448))
	test = Classify(trainFile=baseDir+'workspace/trainMetrics.csv',
					orderFile=baseDir+'moby/corr64.csv',
					useCols=noTime)
	test.testAndOutput(clf=clf,
		testFile=baseDir+'workspace/testMetrics.csv',
		orderFile=baseDir+'moby/testCorr64.csv',
		outfile='submit64.sub')

	# Blend
	s32 = np.loadtxt('submit32.sub',delimiter=',')
	s64 = np.loadtxt('submit64.sub',delimiter=',')
	sub_ = 0.5*s32 + 0.5*s64
	np.savetxt('blend.sub',sub_,delimiter=',')
コード例 #7
0
    def predictor(self):
        if self.sc == None:
            self.sc = scraper(self.keyword).results
        self.articles = len(self.sc)

        for i in self.sc:
            value = Classify(i["title"]).classify()
            self.score += value

        self.final_pred = self.score / self.articles
コード例 #8
0
    def predictor(self):
        sc = scraper(self.keyword).results
        self.articles = len(sc)

        for i in sc:
            value = Classify(i["title"]).classify()
            if value == "Positive":
                self.score += 1

        self.final_pred = self.score / self.articles
コード例 #9
0
    def cl(self):
        global flag
        if (flag == 1):  #From Twitter
            self.cl = Classify()
            a = self.cl.classify_r1()
            self.textEdit_2.setText(a + ' >>')

        if (flag == 0):  #From File

            self.cl = Classify_FileTweet()
            a = self.cl.classify_r1()
            self.textEdit_2.setText(a + ' >>')
コード例 #10
0
def main(maxFeatures=30, maxDepth=8):

    print "maxFeatures:", maxFeatures
    print "maxDepth   :", maxDepth

    baseDir = globalConst.BASE_DIR

    params = {
        'max_depth': maxDepth,
        'subsample': 0.5,
        'verbose': 2,
        'random_state': 0,
        'min_samples_split': 20,
        'min_samples_leaf': 20,
        'max_features': maxFeatures,
        'n_estimators': 500,
        'learning_rate': 0.05
    }
    #'n_estimators': 12000, 'learning_rate': 0.002}
    clf = GradientBoostingClassifier(**params)

    # NOTE: first pass, no orderFile; 2nd pass, use orderfiles
    test = Classify(trainFile=baseDir + 'workspace/trainMetrics.csv',
                    orderFile=useIfExists(baseDir + '/moby/corr32.csv'))

    test.validate(clf=clf,
                  nFolds=2,
                  featureImportance=True,
                  outFile=baseDir + 'moby/trainPredictions.csv')

    test.testAndOutput(clf=clf,
                       testFile=baseDir + 'workspace/testMetrics.csv',
                       orderFile=useIfExists(baseDir + '/moby/testCorr32.csv'),
                       outfile=baseDir +
                       'moby/testPredictions.sub')  # NOTE .sub, not .csv
コード例 #11
0
    def cl(self):
        global flag
        if (flag == 1):  #From Twitter
            self.cl = Classify()
            a = self.cl.classify_r1()
            self.textEdit_2.setText(a + ' >>')
            b = self.cl.classify_r2(a)
            self.textEdit_2.append(b + ' >>')
            c = self.cl.classify_r3(b)
            self.textEdit_2.append(c + ' >>')
            d = self.cl.classify_r4(c)
            self.textEdit_2.append(d)

        if (flag == 0):  #From File

            self.cl = Classify_FileTweet()
            a = self.cl.classify_r1()
            self.textEdit_2.setText(a + ' >>')
            b = self.cl.classify_r2(a)
            self.textEdit_2.append(b + ' >>')
            c = self.cl.classify_r3(b)
            self.textEdit_2.append(c + ' >>')
            d = self.cl.classify_r4(c)
            self.textEdit_2.append(d)
コード例 #12
0
ファイル: run.py プロジェクト: zhssakura/enrichM
    def main(self, args, command):
        '''
        Parameters
        ----------
        
        Output
        ------
        '''

        self._check_general(args)
        self._logging_setup(args)

        logging.info("Running command: %s" % ' '.join(command))

        if args.subparser_name == self.DATA:
            self._check_data(args)
            d = Data()

            d.do()
        
        if args.subparser_name == self.ANNOTATE:
            self._check_annotate(args)
            a = Annotate(# Define inputs and outputs
                         args.output,
                         # Define type of annotation to be carried out
                         args.ko,
                         args.pfam,
                         args.tigrfam,
                         args.cog,
                         args.hypothetical,
                         # Cutoffs
                         args.evalue,
                         args.bit,
                         args.id,
                         args.aln_query, 
                         args.aln_reference, 
                         args.cascaded,
                         args.c,
                         # Parameters
                         args.threads,
                         args.parallel,
                         args.suffix)

            a.do(args.genome_directory, args.protein_directory, 
                 args.genome_files, args.protein_files)

        elif args.subparser_name == self.CLASSIFY:
            self._check_classify(args)
            c = Classify()
            c.do(args.custom_modules, 
                 args.cutoff,
                 args.genome_and_annotation_file,
                 args.genome_and_annotation_matrix,
                 args.output)

        elif args.subparser_name == self.ENRICHMENT: 
            self._check_enrichment(args)
            e = Enrichment()
            e.do(# Inputs
                 args.annotation_matrix,
                 args.annotation_file,
                 args.metadata,
                 args.modules,
                 args.abundances,
                 args.do_all,
                 args.do_ivi, 
                 args.do_gvg,
                 args.do_ivg,
                 args.pval_cutoff,
                 args.proportions_cutoff,
                 args.threshold,
                 args.multi_test_correction,
                 args.output)

        elif args.subparser_name == self.COMPARE:
            self._check_compare(args)
            c = Compare()
            c.do(args.enrichm_annotate_output)

        elif(args.subparser_name == NetworkAnalyser.PATHWAY or
             args.subparser_name == NetworkAnalyser.EXPLORE or
             args.subparser_name == NetworkAnalyser.TRAVERSE):

            self._check_network(args)
            na=NetworkAnalyser(args.metadata)
            na.do(args.matrix,
                  args.transcriptome,
                  args.metabolome,
                  args.depth,
                  args.filter,
                  args.limit,
                  args.queries,
                  args.subparser_name,
                  args.starting_compounds, 
                  args.steps,
                  args.number_of_queries,
                  args.output)
        logging.info('Done!')
コード例 #13
0
ファイル: app.py プロジェクト: Rits1272/StuMap
def save_feedback():
    if request.method == 'POST':
        ques_1 = request.form.get('ques_1')
        ques_2 = request.form.get('ques_2')
        ques_3 = request.form.get('ques_3')
        ques_4 = request.form.get('ques_4')
        opinion = request.form.get('opinion')

        teacher = request.form.get('teacher')
        teacher_obj = Teacher.query.filter(Teacher.name == teacher).one()

        positive_score = Classify(opinion).classify()

        if positive_score > 0.75:
            feedback_obj = Feedback(ques_1=ques_1,
                                    ques_2=ques_2,
                                    ques_3=ques_3,
                                    ques_4=ques_4,
                                    opinion=opinion,
                                    teacher=teacher_obj)
            db.session.add(feedback_obj)
            db.session.commit()

            return make_response("Feedback Posted Successfully!")
        else:
            return make_response(
                "Invalid Feedback. Please check your language quality")
    else:
        query_1 = [
            Feedback.query.filter(Feedback.ques_1.in_([1])).count(),
            Feedback.query.filter(Feedback.ques_1.in_([2])).count(),
            Feedback.query.filter(Feedback.ques_1.in_([3])).count(),
            Feedback.query.filter(Feedback.ques_1.in_([4])).count(),
            Feedback.query.filter(Feedback.ques_1.in_([5])).count()
        ]

        query_2 = [
            Feedback.query.filter(Feedback.ques_2.in_([1])).count(),
            Feedback.query.filter(Feedback.ques_2.in_([2])).count(),
            Feedback.query.filter(Feedback.ques_2.in_([3])).count(),
            Feedback.query.filter(Feedback.ques_2.in_([4])).count(),
            Feedback.query.filter(Feedback.ques_2.in_([5])).count()
        ]

        query_3 = [
            Feedback.query.filter(Feedback.ques_3.in_([1])).count(),
            Feedback.query.filter(Feedback.ques_3.in_([2])).count(),
            Feedback.query.filter(Feedback.ques_3.in_([3])).count(),
            Feedback.query.filter(Feedback.ques_3.in_([4])).count(),
            Feedback.query.filter(Feedback.ques_3.in_([5])).count()
        ]

        query_4 = [
            Feedback.query.filter(Feedback.ques_4.in_([1])).count(),
            Feedback.query.filter(Feedback.ques_4.in_([2])).count(),
            Feedback.query.filter(Feedback.ques_4.in_([3])).count(),
            Feedback.query.filter(Feedback.ques_4.in_([4])).count(),
            Feedback.query.filter(Feedback.ques_4.in_([5])).count()
        ]

        opinion_1 = []
        for i in Feedback.query.all():
            opinion_1.append(i.opinion)
        resp = {
            "query_1": query_1,
            "query_2": query_2,
            "query_3": query_3,
            "ques_4": query_4,
            "opinion": opinion_1
        }
        return jsonify(resp)
コード例 #14
0
class Ui_MainWindow(object):
    def fromfile(self):
        self.fromfile = TweetFetch()
        f = self.fromfile.fetchFromFile()
        self.textEdit.setText(f)
        self.textEdit_3.setText("Tweet Fetched from file")

    def fromtwitter(self):
        self.fromtwitter = TweetFetch()
        self.fromtwitter.status()
        f = self.fromtwitter.fetchFromTwitter()
        self.textEdit.setText(f)
        self.textEdit_3.setText("Tweet Fetched from Twitter")

    def cl(self):
        self.cl = Classify()
        a = self.cl.classify_r1()
        self.textEdit_2.setText(a + ' >>')
        b = self.cl.classify_r2(a)
        self.textEdit_2.append(b)
        self.textEdit_3.setText("Tweet Classfied")

    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(579, 458)

        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")

        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(30, 140, 151, 27))
        self.pushButton.setObjectName("pushButton")
        self.pushButton.clicked.connect(self.fromfile)

        self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_2.setGeometry(QtCore.QRect(90, 300, 85, 27))
        self.pushButton_2.setObjectName("pushButton_2")
        self.pushButton_2.clicked.connect(self.cl)

        self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
        self.textEdit.setGeometry(QtCore.QRect(220, 130, 301, 101))
        self.textEdit.setObjectName("textEdit")
        self.textEdit.setReadOnly(True)

        self.textEdit_2 = QtWidgets.QTextEdit(self.centralwidget)
        self.textEdit_2.setGeometry(QtCore.QRect(220, 250, 301, 171))
        self.textEdit_2.setObjectName("textEdit_2")
        self.textEdit_2.setReadOnly(True)

        self.line = QtWidgets.QFrame(self.centralwidget)
        self.line.setGeometry(QtCore.QRect(0, 230, 611, 16))
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")

        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(20, 10, 541, 20))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.label.setFont(font)
        self.label.setObjectName("label")

        self.textEdit_3 = QtWidgets.QTextEdit(self.centralwidget)
        self.textEdit_3.setGeometry(QtCore.QRect(220, 60, 301, 41))
        self.textEdit_3.setObjectName("textEdit_3")
        self.textEdit_3.setReadOnly(True)

        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(10, 70, 181, 20))
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setItalic(False)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")

        self.line_2 = QtWidgets.QFrame(self.centralwidget)
        self.line_2.setGeometry(QtCore.QRect(0, 110, 601, 16))
        self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_2.setObjectName("line_2")

        self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_3.setGeometry(QtCore.QRect(30, 200, 151, 27))
        self.pushButton_3.setObjectName("pushButton_3")
        self.pushButton_3.clicked.connect(self.fromtwitter)

        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.pushButton.setText(
            _translate("MainWindow", "Fetch Tweet from File"))
        self.pushButton_2.setText(_translate("MainWindow", "Classify"))
        self.label.setText(
            _translate(
                "MainWindow",
                "Welcome to Twitter Classifier! This system classifies tweet into 3 level deep cateorization"
            ))
        self.label_2.setText(
            _translate("MainWindow", "Status of Processing Request"))
        self.pushButton_3.setText(
            _translate("MainWindow", "Fetch Tweet from Twitter"))
コード例 #15
0
def main():
    parser = argparse.ArgumentParser(
        description="process all JSON files in the given directory"
        "outputting the results in the given filename")
    parser.add_argument("parse_dir", help="enter the directory to parse")
    parser.add_argument(
        "output_file", help="enter the file where the results will be written")
    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        help="set verbose output")
    parser.add_argument("-s",
                        "--skip",
                        action="store_true",
                        help="skip parsing the files")
    args = parser.parse_args()

    if args.verbose:
        printer = Printer(True)
    else:
        printer = Printer(False)

    p_dir = args.parse_dir
    output_file = args.output_file

    if not args.skip:
        printer.standard_output(
            'Chosen directory %s. Wait for file: %s to be generated' %
            (p_dir, output_file))
        printer.standard_output('verbose is set to: %r' %
                                printer.get_verbose())

        printer.write_file(output_file, '', 'w')

        parsing = Parser(printer)
        parsing.parse_files(p_dir, output_file)

    in_dir = "docs/"
    in_file = "classify.json"
    classifier = Classify(printer)
    classifier.classify(output_file, in_dir, in_file)

    type = 'apis'
    cat_dir = 'docs/randep-binary-maps/%s/' % type
    grap_dir = 'docs/randep-binary-maps/graphs/'
    plotter = Plot()
    regex = re.compile(r'^(.*?)[-|\.]json')

    for (dir_path, dir_names, file_names) in walk(cat_dir):
        for i, name in enumerate(file_names):
            if name.endswith('.json'):
                # only get the proper name of the file
                file_name = re.match(regex, name).group(1)
                printer.line_comment("Generate graph from json file: " + name)
                api_names, start_times, end_times, state_names, state_starts, state_ends, class_names, class_starts, \
                class_ends, state_dict = \
                    classifier.get_api_data(dir_path + name, type)
                plotter.plots(grap_dir + 'apis/' + file_name, api_names,
                              start_times, end_times)
                plotter.plots(grap_dir + 'states/' + file_name, state_names,
                              state_starts, state_ends)
                plotter.plots(grap_dir + 'classes/' + file_name, class_names,
                              class_starts, class_ends)
                for state in state_dict:
                    plotter.plots(
                        grap_dir + 'states/api_per_state/' + file_name + '-' +
                        state, state_dict[state]['apis'],
                        state_dict[state]['starts'], state_dict[state]['ends'])