def _set_item(self, i, j, item):
self.tablemodel.setItem(i, j, item)
def set_results(self, results):
Set the input results.
prev_sel_learner = self.selected_learner[:]
self.clear()
self.warning([0, 1])
self.closeContext()
data = None
if results is not None:
if results.data is not None:
data = results.data
if data is not None and not data.domain.has_discrete_class:
data = None
results = None
self.warning(
0, "Confusion Matrix cannot be used for regression results.")
self.results = results
self.data = data
if data is not None:
class_values = data.domain.class_var.values
elif results is not None:
raise NotImplementedError
if results is None:
self.report_button.setDisabled(True)
else:
self.report_button.setDisabled(False)
nmodels, ntests = results.predicted.shape
self.headers = class_values + \
[unicodedata.lookup("N-ARY SUMMATION")]
// NOTE: The "learner_names" is set in
// "Test Learners" widget.
if hasattr(results, "learner_names"):
self.learners = results.learner_names
else:
self.learners = ["Learner //%i" % (i + 1)
for i in range(nmodels)]
item = self._item(0, 2)
item.setData("Predicted", Qt.DisplayRole)
item.setTextAlignment(Qt.AlignCenter)
item.setFlags(Qt.NoItemFlags)
self._set_item(0, 2, item)
item = self._item(2, 0)
item.setData("Actual", Qt.DisplayRole)
item.setTextAlignment(Qt.AlignHCenter | Qt.AlignBottom)
item.setFlags(Qt.NoItemFlags)
self.tableview.setItemDelegateForColumn(
0, gui.VerticalItemDelegate())
self._set_item(2, 0, item)
self.tableview.setSpan(0, 2, 1, len(class_values))
self.tableview.setSpan(2, 0, len(class_values), 1)
font = self.tablemodel.invisibleRootItem().font()
bold_font = QFont(font)
bold_font.setBold(True)
for i in (0, 1):
for j in (0, 1):
item = self._item(i, j)
item.setFlags(Qt.NoItemFlags)
self._set_item(i, j, item)
for p, label in enumerate(self.headers):
for i, j in ((1, p + 2), (p + 2, 1)):
item = self._item(i, j)
item.setData(label, Qt.DisplayRole)
item.setFont(bold_font)
item.setTextAlignment(Qt.AlignRight | Qt.AlignVCenter)
item.setFlags(Qt.ItemIsEnabled)
if p < len(self.headers) - 1:
item.setData("br"[j == 1], BorderRole)
item.setData(QColor(192, 192, 192), BorderColorRole)
self._set_item(i, j, item)
hor_header = self.tableview.horizontalHeader()
if len(" ".join(self.headers)) < 120:
hor_header.setResizeMode(QHeaderView.ResizeToContents)
else:
hor_header.setDefaultSectionSize(60)
self.tablemodel.setRowCount(len(class_values) + 3)
self.tablemodel.setColumnCount(len(class_values) + 3)
self.openContext(data.domain.class_var)
if not prev_sel_learner or \
prev_sel_learner[0] >= len(self.learners):
self.selected_learner[:] = [0]
else:
self.selected_learner[:] = prev_sel_learner
def clear(self):
self.results = None