Example #1
0
    def classificationReport(self, doEvalSet=False):

        if doEvalSet:  #produce report for dev and eval sets instead
            X_test = self.data.X_eval
            y_test = self.data.y_eval
            X_train = self.data.X_dev
            y_train = self.data.y_dev
            append = '_eval'
        else:
            X_test = self.data.X_test
            y_test = self.data.y_test
            X_train = self.data.X_train
            y_train = self.data.y_train
            append = ''

        if not os.path.exists(self.output): os.makedirs(self.output)
        f = open(
            os.path.join(self.output,
                         'classificationReport' + append + '.txt'), 'w')
        f.write('Performance on test set:')
        classificationReport(self.bdt.predict(X_test),
                             self.bdt.decision_function(X_test), y_test, f)

        f.write('\n')
        f.write('Performance on training set:')
        classificationReport(self.bdt.predict(X_train),
                             self.bdt.decision_function(X_train), y_train, f)

        if self.crossValResults is not None:
            f.write('\n\nCross Validation\n')
            f.write("Cross val results: %.2f%% (%.2f%%)" %
                    (self.crossValResults.mean() * 100,
                     self.crossValResults.std() * 100))
Example #2
0
    def classificationReport(self, doEvalSet=False, batchSize=32):

        if doEvalSet:  #produce report for dev and eval sets instead
            X_test = self.data.X_eval
            y_test = self.data.y_eval
            weights_test = self.data.weights_eval
            X_train = self.data.X_dev
            y_train = self.data.y_dev
            weights_train = self.data.weights_dev
            append = '_eval'
        else:
            X_test = self.data.X_test
            y_test = self.data.y_test
            weights_test = self.data.weights_test
            X_train = self.data.X_train
            y_train = self.data.y_train
            weights_train = self.data.weights_train
            append = ''

        if not os.path.exists(self.output): os.makedirs(self.output)
        f = open(
            os.path.join(self.output,
                         'classificationReport' + append + '.txt'), 'w')

        f.write('Performance on test set:\n')
        report = self.model.evaluate(X_test.as_matrix(),
                                     y_test.as_matrix(),
                                     sample_weight=weights_test,
                                     batch_size=batchSize)
        self.score = report

        if self.doRegression:
            f.write('\n\nDNN Loss, Mean Squared Error:\n')
        else:
            classificationReport(
                self.model.predict_classes(X_test.as_matrix()),
                self.model.predict(X_test.as_matrix()), y_test, f)
            f.write('\n\nDNN Loss, Accuracy, Significance:\n')
        f.write(str(report))

        f.write('\n\nPerformance on train set:\n')
        report = self.model.evaluate(X_train.as_matrix(),
                                     y_train.as_matrix(),
                                     sample_weight=weights_train,
                                     batch_size=batchSize)
        if self.doRegression:
            f.write('\n\nDNN Loss, Mean Squared Error:\n')
        else:
            classificationReport(
                self.model.predict_classes(X_train.as_matrix()),
                self.model.predict(X_train.as_matrix()), y_train, f)
            f.write('\n\nDNN Loss, Accuracy, Significance:\n')
        f.write(str(report))

        if self.crossValResults is not None:
            f.write('\n\nCross Validation\n')
            f.write("Cross val results: %.2f%% (%.2f%%)" %
                    (self.crossValResults.mean() * 100,
                     self.crossValResults.std() * 100))