Пример #1
0
    def test_plot_confusion_matrix(self):
        cf_cv = ClassifierCv(self.labels, self.texts)
        name = 'MultinomialNB'
        metric = 'f1'
        cf_cv.train_save_metrics([
            ('vect', CountVectorizer()),
            ('tfidf', TfidfTransformer()),
            ('clf', MultinomialNB(alpha=.05)),
        ], metric, name, self.test_dir, self.test_dir)

        filename = os.path.join(self.test_dir, name + '_confusion_matrix.png')
        cf_cv.plot_confusion_matrix(savefile=filename)
        self.assertTrue(os.path.isfile(filename))
Пример #2
0
    def test_plot_confusion_matrix_eval_data_normalize(self):
        cf_cv = ClassifierCv(self.labels, self.texts)
        name = 'MultinomialNB'
        metric = 'f1'
        cf_cv.train_save_metrics([
            ('vect', CountVectorizer()),
            ('tfidf', TfidfTransformer()),
            ('clf', MultinomialNB(alpha=.05)),
        ], metric, name, self.test_dir, self.test_dir)

        filename = os.path.join(self.test_dir,
                                name + 'eval_confusion_matrix.png')
        cf_cv.labels_eval_real = ['pos', 'neg', 'neg', 'neg']
        cf_cv.labels_eval_predicted = ['pos', 'neg', 'neg', 'neg']

        cf_cv.plot_confusion_matrix(savefile=filename,
                                    normalize=True,
                                    use_evaluation_data=True)
        self.assertTrue(os.path.isfile(filename))