added classification using log theta
@@ -2,6 +2,7 @@ from evaluation_metrics.metrics import Abstract_Metric
import configuration.citations as citations
import configuration.defaults as defaults
from sklearn.metrics import f1_score, confusion_matrix
+import numpy as np
from sklearn import svm
@@ -9,6 +10,8 @@ class F1Score(Abstract_Metric):
def __init__(self, metric_parameters={}):
Abstract_Metric.__init__(self, metric_parameters)
+ self.train_document_representations = None
+ self.test_document_representations = None
parameters = defaults.em_f1_score.copy()
parameters.update(metric_parameters)
if 'dataset' not in metric_parameters.keys():
@@ -16,6 +19,10 @@ class F1Score(Abstract_Metric):
else:
self.labels = metric_parameters['dataset'].get_labels()
self.average = parameters['average']
+ if 'use_log' in metric_parameters:
+ self.use_log = metric_parameters['use_log']
+ else:
+ self.use_log = False
def info(self):
return {
@@ -37,22 +44,18 @@ class F1Score(Abstract_Metric):
-------
score : score
"""
-
self.train_document_representations = model_output["topic-document-matrix"].T
- self.test_documents_representations = model_output["test-topic-document-matrix"].T
-
- if len(self.labels) != len(self.train_document_representations) + len(self.test_documents_representations):
- print(len(self.labels))
- print(len(self.train_document_representations))
- print(len(self.test_documents_representations))
- raise Exception('Dimension of labels (', len(self.labels),
- ') different from dimension of docs (',
- len(self.train_document_representations) + len(self.test_documents_representations), ')')
- else:
+ self.test_document_representations = model_output["test-topic-document-matrix"].T
+ if self.use_log:
+ self.train_document_representations = np.log(self.train_document_representations)
+ self.test_document_representations = np.log(self.test_document_representations)
+
+
train_labels = [l[0] for l in self.labels[:len(self.train_document_representations)]]
- test_labels = [l[0] for l in self.labels[len(self.train_document_representations):]]
+ test_labels = [l[0] for l in self.labels[
+ -len(self.test_documents_representations):]]
- clf = svm.LinearSVC()
+ clf = svm.SVC(kernel='poly')
clf.fit(self.train_document_representations, train_labels)
predicted_test_labels = clf.predict(self.test_documents_representations)
