예제 #1
0
    def test_tooltips(self):
        data_in = Orange.data.Table("titanic")
        res = Orange.evaluation.TestOnTrainingData(
            data=data_in,
            learners=[
                Orange.classification.KNNLearner(),
                Orange.classification.LogisticRegressionLearner()
            ],
            store_data=True)

        self.send_signal(self.widget.Inputs.evaluation_results, res)
        self.widget.roc_averaging = OWROCAnalysis.Merge
        self.widget.target_index = 0
        self.widget.selected_classifiers = [0, 1]
        vb = self.widget.plot.getViewBox()
        vb.childTransform()  # Force pyqtgraph to update transforms

        curve = self.widget.plot_curves(self.widget.target_index, 0)
        curve_merge = curve.merge()
        view = self.widget.plotview
        item = curve_merge.curve_item  # type: pg.PlotCurveItem

        # no tooltips to be shown
        pos = item.mapToScene(0.0, 1.0)
        pos = view.mapFromScene(pos)
        mouseMove(view.viewport(), pos)
        self.assertIs(self.widget._tooltip_cache, None)

        # test single point
        pos = item.mapToScene(0.22504, 0.45400)
        pos = view.mapFromScene(pos)
        mouseMove(view.viewport(), pos)
        shown_thresh = self.widget._tooltip_cache[1]
        self.assertTrue(QToolTip.isVisible())
        np.testing.assert_almost_equal(shown_thresh, [0.40000], decimal=5)

        pos = item.mapToScene(0.0, 0.0)
        pos = view.mapFromScene(pos)
        # test overlapping points
        mouseMove(view.viewport(), pos)
        shown_thresh = self.widget._tooltip_cache[1]
        self.assertTrue(QToolTip.isVisible())
        np.testing.assert_almost_equal(shown_thresh, [1.8, 1.89336], decimal=5)

        # test that cache is invalidated when changing averaging mode
        self.widget.roc_averaging = OWROCAnalysis.Threshold
        self.widget._replot()
        mouseMove(view.viewport(), pos)
        shown_thresh = self.widget._tooltip_cache[1]
        self.assertTrue(QToolTip.isVisible())
        np.testing.assert_almost_equal(shown_thresh, [1, 1])

        # test nan thresholds
        self.widget.roc_averaging = OWROCAnalysis.Vertical
        self.widget._replot()
        mouseMove(view.viewport(), pos)
        self.assertIs(self.widget._tooltip_cache, None)
예제 #2
0
    def test_tooltips(self):
        data_in = Orange.data.Table("titanic")
        res = Orange.evaluation.TestOnTrainingData(
            data=data_in,
            learners=[Orange.classification.KNNLearner(),
                      Orange.classification.LogisticRegressionLearner()],
            store_data=True
        )

        self.send_signal(self.widget.Inputs.evaluation_results, res)
        self.widget.roc_averaging = OWROCAnalysis.Merge
        self.widget.target_index = 0
        self.widget.selected_classifiers = [0, 1]
        vb = self.widget.plot.getViewBox()
        vb.childTransform()  # Force pyqtgraph to update transforms

        curve = self.widget.plot_curves(self.widget.target_index, 0)
        curve_merge = curve.merge()
        view = self.widget.plotview
        item = curve_merge.curve_item  # type: pg.PlotCurveItem

        # no tooltips to be shown
        pos = item.mapToScene(0.0, 1.0)
        pos = view.mapFromScene(pos)
        mouseMove(view.viewport(), pos)
        self.assertIs(self.widget._tooltip_cache, None)

        # test single point
        pos = item.mapToScene(0.22504, 0.45400)
        pos = view.mapFromScene(pos)
        mouseMove(view.viewport(), pos)
        shown_thresh = self.widget._tooltip_cache[1]
        self.assertTrue(QToolTip.isVisible())
        np.testing.assert_almost_equal(shown_thresh, [0.40000], decimal=5)

        pos = item.mapToScene(0.0, 0.0)
        pos = view.mapFromScene(pos)
        # test overlapping points
        mouseMove(view.viewport(), pos)
        shown_thresh = self.widget._tooltip_cache[1]
        self.assertTrue(QToolTip.isVisible())
        np.testing.assert_almost_equal(shown_thresh, [1.8, 1.89336], decimal=5)

        # test that cache is invalidated when changing averaging mode
        self.widget.roc_averaging = OWROCAnalysis.Threshold
        self.widget._replot()
        mouseMove(view.viewport(), pos)
        shown_thresh = self.widget._tooltip_cache[1]
        self.assertTrue(QToolTip.isVisible())
        np.testing.assert_almost_equal(shown_thresh, [1, 1])

        # test nan thresholds
        self.widget.roc_averaging = OWROCAnalysis.Vertical
        self.widget._replot()
        mouseMove(view.viewport(), pos)
        self.assertIs(self.widget._tooltip_cache, None)
예제 #3
0
    def test_tooltips(self):
        data_in = Orange.data.Table("titanic")
        res = Orange.evaluation.TestOnTrainingData(
            data=data_in,
            learners=[
                Orange.classification.KNNLearner(),
                Orange.classification.LogisticRegressionLearner()
            ],
            store_data=True)

        self.send_signal(self.widget.Inputs.evaluation_results, res)
        self.widget.roc_averaging = OWROCAnalysis.Merge
        self.widget.target_index = 0
        self.widget.selected_classifiers = [0, 1]
        vb = self.widget.plot.getViewBox()
        vb.childTransform()  # Force pyqtgraph to update transforms

        curve = self.widget.plot_curves(self.widget.target_index, 0)
        curve_merge = curve.merge()
        view = self.widget.plotview
        item = curve_merge.curve_item  # type: pg.PlotCurveItem

        with patch.object(QToolTip, "showText") as show_text:
            # no tooltips to be shown
            pos = item.mapToScene(0.0, 1.0)
            pos = view.mapFromScene(pos)
            mouseMove(view.viewport(), pos)
            show_text.assert_not_called()

            # test single point
            pos = item.mapToScene(0.22504, 0.45400)
            pos = view.mapFromScene(pos)
            mouseMove(view.viewport(), pos)
            (_, text), _ = show_text.call_args
            self.assertIn("(#1) 0.400", text)

            # test overlapping points
            pos = item.mapToScene(0.0, 0.0)
            pos = view.mapFromScene(pos)
            mouseMove(view.viewport(), pos)
            (_, text), _ = show_text.call_args
            self.assertIn("(#1) 1.800\n(#2) 1.893", text)

            # test that cache is invalidated when changing averaging mode
            self.widget.roc_averaging = OWROCAnalysis.Threshold
            self.widget._replot()
            mouseMove(view.viewport(), pos)
            (_, text), _ = show_text.call_args
            self.assertIn("(#1) 1.000\n(#2) 1.000", text)

            # test nan thresholds
            self.widget.roc_averaging = OWROCAnalysis.Vertical
            self.widget._replot()
            mouseMove(view.viewport(), pos)
            (_, text), _ = show_text.call_args
            self.assertEqual(text, "")
예제 #4
0
 def test_track(self):
     cb = self.cb
     cb.setStyleSheet("combobox-list-mousetracking: 1")
     cb.showPopup()
     popup = cb.findChild(QListView)  # type: QListView
     model = popup.model()
     rect = popup.visualRect(model.index(2, 0))
     mouseMove(popup.viewport(), rect.center())
     self.assertEqual(popup.currentIndex().row(), 2)
     cb.hidePopup()
예제 #5
0
    def test_tooltips(self):
        data_in = Orange.data.Table("titanic")
        res = Orange.evaluation.TestOnTrainingData(
            data=data_in,
            learners=[Orange.classification.KNNLearner(),
                      Orange.classification.LogisticRegressionLearner()],
            store_data=True
        )

        self.send_signal(self.widget.Inputs.evaluation_results, res)
        self.widget.roc_averaging = OWROCAnalysis.Merge
        self.widget.target_index = 0
        self.widget.selected_classifiers = [0, 1]
        vb = self.widget.plot.getViewBox()
        vb.childTransform()  # Force pyqtgraph to update transforms

        curve = self.widget.plot_curves(self.widget.target_index, 0)
        curve_merge = curve.merge()
        view = self.widget.plotview
        item = curve_merge.curve_item  # type: pg.PlotCurveItem

        with patch.object(QToolTip, "showText") as show_text:
            # no tooltips to be shown
            pos = item.mapToScene(0.0, 1.0)
            pos = view.mapFromScene(pos)
            mouseMove(view.viewport(), pos)
            show_text.assert_not_called()

            # test single point
            pos = item.mapToScene(0.22504, 0.45400)
            pos = view.mapFromScene(pos)
            mouseMove(view.viewport(), pos)
            (_, text), _ = show_text.call_args
            self.assertIn("(#1) 0.400", text)

            # test overlapping points
            pos = item.mapToScene(0.0, 0.0)
            pos = view.mapFromScene(pos)
            mouseMove(view.viewport(), pos)
            (_, text), _ = show_text.call_args
            self.assertIn("(#1) 1.800\n(#2) 1.893", text)

            # test that cache is invalidated when changing averaging mode
            self.widget.roc_averaging = OWROCAnalysis.Threshold
            self.widget._replot()
            mouseMove(view.viewport(), pos)
            (_, text), _ = show_text.call_args
            self.assertIn("(#1) 1.000\n(#2) 1.000", text)

            # test nan thresholds
            self.widget.roc_averaging = OWROCAnalysis.Vertical
            self.widget._replot()
            mouseMove(view.viewport(), pos)
            (_, text), _ = show_text.call_args
            self.assertEqual(text, "")
예제 #6
0
    def test_tooltips(self):
        # See https://people.inf.elte.hu/kiss/11dwhdm/roc.pdf for the curve
        # representing this data
        actual = np.array([float(c == "n") for c in "ppnpppnnpnpnpnnnpnpn"])
        p = np.array([
            .9, .8, .7, .6, .55, .54, .53, .52, .51, .505, .4, .39, .38, .37,
            .36, .35, .34, .33, .30, .1
        ])
        n = 1 - p
        predicted = (p > .5).astype(float)

        # The second curve is like the first except for the first three points:
        # it goes to the right and then up
        p2 = p.copy()
        p2[:4] = [0.7, 0.8, 0.9, 0.59]
        n2 = 1 - p2
        predicted2 = (p2 < .5).astype(float)

        data = Orange.data.Table(
            Orange.data.Domain(
                [], [Orange.data.DiscreteVariable("y", values=tuple("pn"))]),
            np.empty((len(p), 0), dtype=float), actual)
        res = Results(data=data,
                      actual=actual,
                      predicted=np.array([list(predicted),
                                          list(predicted2)]),
                      probabilities=np.array(
                          [list(zip(p, n)), list(zip(p2, n2))]))
        self.send_signal(self.widget.Inputs.evaluation_results, res)
        self.widget.roc_averaging = OWROCAnalysis.Merge
        self.widget.target_index = 0
        self.widget.selected_classifiers = [0, 1]
        vb = self.widget.plot.getViewBox()
        vb.childTransform()  # Force pyqtgraph to update transforms

        curve = self.widget.plot_curves(self.widget.target_index, 0)
        curve_merge = curve.merge()
        view = self.widget.plotview
        item = curve_merge.curve_item  # type: pg.PlotCurveItem

        with patch.object(QToolTip, "showText") as show_text:
            # no tooltips to be shown
            pos = item.mapToScene(0.0, 1.0)
            pos = view.mapFromScene(pos)
            mouseMove(view.viewport(), pos)
            show_text.assert_not_called()

            # test single point
            pos = item.mapToScene(0, 0.1)
            pos = view.mapFromScene(pos)
            mouseMove(view.viewport(), pos)
            (_, text), _ = show_text.call_args
            self.assertIn("(#1) 0.900", text)
            self.assertNotIn("#2", text)

            # test overlapping points
            pos = item.mapToScene(0.0, 0.0)
            pos = view.mapFromScene(pos)
            mouseMove(view.viewport(), pos)
            (_, text), _ = show_text.call_args
            self.assertIn("(#1) 1.000\n(#2) 1.000", text)

            pos = item.mapToScene(0.1, 0.3)
            pos = view.mapFromScene(pos)
            mouseMove(view.viewport(), pos)
            (_, text), _ = show_text.call_args
            self.assertIn("(#1) 0.600\n(#2) 0.590", text)
            show_text.reset_mock()

            # test that cache is invalidated when changing averaging mode
            self.widget.roc_averaging = OWROCAnalysis.Threshold
            self.widget._replot()
            mouseMove(view.viewport(), pos)
            (_, text), _ = show_text.call_args
            self.assertIn("(#1) 0.600\n(#2) 0.590", text)
            show_text.reset_mock()

            # test nan thresholds
            self.widget.roc_averaging = OWROCAnalysis.Vertical
            self.widget._replot()
            mouseMove(view.viewport(), pos)
            show_text.assert_not_called()