Skip to content

Commit

Permalink
Nomogram: Retain original compute_value
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Apr 2, 2021
1 parent 704a837 commit c0174f9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions Orange/widgets/visualize/ownomogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,7 @@ def reconstruct_domain(original, preprocessed):
for attr in preprocessed.attributes:
cv = attr._compute_value.variable._compute_value
var = cv.variable if cv else original[attr.name]
var = original[var.name] if var.name in original else attr
if var in attrs: # the reason for OrderedDict
continue
attrs[var] = None # we only need keys
Expand Down
23 changes: 23 additions & 0 deletions Orange/widgets/visualize/tests/test_ownomogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from Orange.classification import (
NaiveBayesLearner, LogisticRegressionLearner, MajorityLearner
)
from Orange.preprocess import Scale, Continuize
from Orange.tests import test_filename
from Orange.widgets.tests.base import WidgetTest
from Orange.widgets.utils.state_summary import format_summary_details
Expand Down Expand Up @@ -306,6 +307,28 @@ def test_dots_stop_flashing(self):
anim = animator._GraphicsColorAnimator__animation
self.assertNotEqual(anim.state(), QPropertyAnimation.Running)

def test_reconstruct_domain(self):
data = Table("heart_disease")
cls = LogisticRegressionLearner()(data)
domain = OWNomogram.reconstruct_domain(cls.original_domain, cls.domain)
transformed_data = cls.original_data.transform(domain)
self.assertEqual(transformed_data.X.shape, data.X.shape)
self.assertFalse(np.isnan(transformed_data.X[0]).any())

scaled_data = Scale()(data)
cls = LogisticRegressionLearner()(scaled_data)
domain = OWNomogram.reconstruct_domain(cls.original_domain, cls.domain)
transformed_data = cls.original_data.transform(domain)
self.assertEqual(transformed_data.X.shape, scaled_data.X.shape)
self.assertFalse(np.isnan(transformed_data.X[0]).any())

disc_data = Continuize()(data)
cls = LogisticRegressionLearner()(disc_data)
domain = OWNomogram.reconstruct_domain(cls.original_domain, cls.domain)
transformed_data = cls.original_data.transform(domain)
self.assertEqual(transformed_data.X.shape, disc_data.X.shape)
self.assertFalse(np.isnan(transformed_data.X[0]).any())


if __name__ == "__main__":
unittest.main()

0 comments on commit c0174f9

Please sign in to comment.