Esempio n. 1
0
    def train_network(self):
        """ Pure virtual method for training the network
        """
        db_query = self._database_session.query(PregamePitcherGameEntry)
        mlb_training_data, mlb_evaluation_data = self.get_train_eval_data(
            db_query, 0.8)
        X_train, Y_train = self.get_stochastic_batch(mlb_training_data,
                                                     self.SIZE_TRAINING_BATCH)
        self._decision_tree.fit(X_train, Y_train)
        dot_data = StringIO()
        tree.export_graphviz(
            self._decision_tree,
            out_file=dot_data,
            feature_names=PregamePitcherGameEntry.get_input_vector_labels())
        graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
        graph.write_pdf("pitcher_tree.pdf")
        x_test_actual = list()
        y_test_actual = list()
        for data in mlb_evaluation_data:
            postgame_entry = self._database_session.query(
                PostgamePitcherGameEntry).get(
                    (data.rotowire_id, data.game_date))

            if postgame_entry is None:
                print "Ignoring hitter %s since his postgame stats were not found." % data.rotowire_id
                continue

            y_test_actual.append([postgame_entry.actual_draftkings_points])
            x_test_actual.append(data.to_input_vector())

        self._database_session.close()
    def train_network(self):
        """ Pure virtual method for training the network
        """
        db_query = self._database_session.query(PregamePitcherGameEntry)
        mlb_training_data, mlb_evaluation_data = self.get_train_eval_data(db_query, 0.8)
        X_train, Y_train = self.get_stochastic_batch(mlb_training_data, self.SIZE_TRAINING_BATCH)
        self._decision_tree.fit(X_train, Y_train)
        dot_data = StringIO()
        tree.export_graphviz(self._decision_tree, out_file=dot_data,
                             feature_names=PregamePitcherGameEntry.get_input_vector_labels())
        graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
        graph.write_pdf("pitcher_tree.pdf")
        x_test_actual = list()
        y_test_actual = list()
        for data in mlb_evaluation_data:
            try:
                postgame_entry = self._database_session.query(PostgamePitcherGameEntry).filter(PostgamePitcherGameEntry.rotowire_id == data.rotowire_id,
                                                                                              PostgamePitcherGameEntry.game_date == data.game_date).one()
                y_test_actual.append([postgame_entry.actual_draftkings_points])
                x_test_actual.append(data.to_input_vector())
            except NoResultFound:
                print "Ignoring hitter %s since his postgame stats were not found." % data.rotowire_id
                continue

        self._database_session.close()