Skip to content

Commit

Permalink
Fix number of decimals and layout of Test Learners table
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Jan 9, 2015
1 parent 0da25c6 commit b419679
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions Orange/widgets/evaluate/owtestlearners.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import numpy

from PyQt4 import QtGui
from PyQt4.QtGui import QTreeView, QStandardItemModel, QStandardItem
from PyQt4.QtCore import Qt
from PyQt4.QtGui import QTreeView, QStandardItemModel, QStandardItem, \
QHeaderView, QItemDelegate
from PyQt4.QtCore import Qt, QSize

import Orange.data
import Orange.classification
Expand All @@ -30,20 +31,26 @@ def classification_stats(results):
classification_stats.headers = ["CA", "F1", "Precision", "Recall"]
classification_stats.headers_binary = ["AUC"]


def regression_stats(results):
return (MSE(results),
RMSE(results),
MAE(results),
R2(results))


regression_stats.headers = ["MSE", "RMSE", "MAE", "R2"]


def is_discrete(var):
return isinstance(var, Orange.data.DiscreteVariable)


class ItemDelegate(QItemDelegate):
def sizeHint(self, *args):
size = super().sizeHint(*args)
return QSize(size.width(), size.height() + 6)


class OWTestLearners(widget.OWWidget):
name = "Test Learners"
description = ""
Expand Down Expand Up @@ -111,9 +118,14 @@ def __init__(self, parent=None):
wordWrap=True,
editTriggers=QTreeView.NoEditTriggers
)
header = self.view.header()
header.setResizeMode(QHeaderView.ResizeToContents)
header.setDefaultAlignment(Qt.AlignCenter)
header.setStretchLastSection(False)

self.result_model = QStandardItemModel()
self.view.setModel(self.result_model)
self.view.setItemDelegate(ItemDelegate())
self._update_header()
box = gui.widgetBox(self.mainArea, "Evaluation Results")
box.layout().addWidget(self.view)
Expand Down Expand Up @@ -217,7 +229,7 @@ def _update_header(self):
for i in reversed(range(len(headers),
self.result_model.columnCount())):
self.result_model.takeColumn(i)

self.result_model.setHorizontalHeaderLabels(headers)

def _update_stats_model(self):
Expand All @@ -234,12 +246,10 @@ def _update_stats_model(self):
row.append(head)
for stat in input.stats:
item = QStandardItem()
item.setData(float(stat[0]), Qt.DisplayRole)
item.setData(" {:.3f} ".format(stat[0]), Qt.DisplayRole)
row.append(item)
model.appendRow(row)

self.view.resizeColumnToContents(0)

def _invalidate(self, which=None):
if which is None:
which = self.learners.keys()
Expand Down

0 comments on commit b419679

Please sign in to comment.