11# pylint: disable=missing-docstring
2+ import numpy as np
23
34from Orange .data import Table
45from Orange .classification import NaiveBayesLearner , TreeLearner
56from Orange .regression import MeanLearner
6- from Orange .evaluation .testing import CrossValidation , TestOnTrainingData
7+ from Orange .evaluation .testing import CrossValidation , TestOnTrainingData , \
8+ ShuffleSplit
79from Orange .widgets .evaluate .owconfusionmatrix import OWConfusionMatrix
810from Orange .widgets .tests .base import WidgetTest , WidgetOutputsTestMixin
911
@@ -16,11 +18,11 @@ def setUpClass(cls):
1618
1719 bayes = NaiveBayesLearner ()
1820 tree = TreeLearner ()
19- iris = cls .data
21+ cls . iris = cls .data
2022 titanic = Table ("titanic" )
2123 common = dict (k = 3 , store_data = True )
22- cls .results_1_iris = CrossValidation (iris , [bayes ], ** common )
23- cls .results_2_iris = CrossValidation (iris , [bayes , tree ], ** common )
24+ cls .results_1_iris = CrossValidation (cls . iris , [bayes ], ** common )
25+ cls .results_2_iris = CrossValidation (cls . iris , [bayes , tree ], ** common )
2426 cls .results_2_titanic = CrossValidation (titanic , [bayes , tree ],
2527 ** common )
2628
@@ -59,8 +61,7 @@ def _select_data(self):
5961 def test_show_error_on_regression (self ):
6062 """On regression data, the widget must show error"""
6163 housing = Table ("housing" )
62- results = TestOnTrainingData (housing , [MeanLearner ()])
63- results .data = housing
64+ results = TestOnTrainingData (housing , [MeanLearner ()], store_data = True )
6465 self .send_signal ("Evaluation Results" , results )
6566 self .assertTrue (self .widget .Error .no_regression .is_shown ())
6667 self .send_signal ("Evaluation Results" , None )
@@ -69,3 +70,15 @@ def test_show_error_on_regression(self):
6970 self .assertTrue (self .widget .Error .no_regression .is_shown ())
7071 self .send_signal ("Evaluation Results" , self .results_1_iris )
7172 self .assertFalse (self .widget .Error .no_regression .is_shown ())
73+
74+ def test_row_indices (self ):
75+ """Map data instances when using random shuffling"""
76+ results = ShuffleSplit (self .iris , [NaiveBayesLearner ()],
77+ store_data = True )
78+ self .send_signal ("Evaluation Results" , results )
79+ self .widget .select_correct ()
80+ selected = self .get_output ("Selected Data" )
81+ correct = np .equal (results .actual , results .predicted )[0 ]
82+ correct_indices = results .row_indices [correct ]
83+ self .assertSetEqual (set (self .iris [correct_indices ].ids ),
84+ set (selected .ids ))
0 commit comments