Exemple #1
0
 def test_regression(self):
     sf = StackedFitter([TreeLearner(), KNNLearner()])
     cv = CrossValidation(k=3, random_state=0)
     results = cv(self.housing[:50], [sf, TreeLearner(), KNNLearner()])
     mse = MSE()(results)
     self.assertLess(mse[0], mse[1])
     self.assertLess(mse[0], mse[2])
 def test_regression(self):
     sf = StackedFitter([TreeLearner(), KNNLearner()])
     results = CrossValidation(
         self.housing[:50],
         [sf, TreeLearner(), KNNLearner()], k=3)
     mse = MSE(results)
     self.assertLess(mse[0], mse[1])
     self.assertLess(mse[0], mse[2])
Exemple #3
0
 def test_error_message_cleared_when_valid_learner_on_input(self):
     # Disconnecting an invalid learner should use the default one and hide
     # the error
     self.send_signal("Learner", KNNLearner())
     self.send_signal('Learner', None)
     self.assertFalse(self.widget.Error.no_weight_support.is_shown(),
                      'Error message was not hidden on input disconnect')
     # Connecting a valid learner should also reset the error message
     self.send_signal("Learner", KNNLearner())
     self.send_signal('Learner', RandomForestLearner())
     self.assertFalse(
         self.widget.Error.no_weight_support.is_shown(),
         'Error message was not hidden when a valid learner appeared on '
         'input')
    def test_coverage(self):
        # Due to async nature of these calls, these tests just cover
        self.send_signal(self.widget.Inputs.data, self.data)
        self.send_signal(self.widget.Inputs.learner, KNNLearner())
        self.widget.class_attr = 'cls'
        self.widget.handleNewSignals()

        self.widget.map.fit_to_bounds()
        self.widget.map.selected_area(90, 180, -90, -180)
        self.widget.map.set_map_provider(
            next(iter(self.widget.TILE_PROVIDERS.values())))
        self.widget.map.set_clustering(True)
        self.widget.map.set_clustering(False)
        self.widget.map.set_jittering(5)
        self.widget.map.set_marker_color('latitude')
        self.widget.map.set_marker_label('latitude')
        self.widget.map.set_marker_shape('foo')
        self.widget.map.set_marker_size('latitude')
        self.process_events(until=lambda start_time=time.clock(): time.clock()
                            - start_time > .2)
        self.widget.map.set_marker_color(None)
        self.widget.map.set_marker_label(None)
        self.widget.map.set_marker_shape(None)
        self.widget.map.set_marker_size(None)
        self.widget.map.set_marker_size_coefficient(50)
        self.widget.map.set_marker_opacity(20)
        self.widget.map.recompute_heatmap(np.random.random((20, 2)))

        args = [100, 100, -100, -100, 1000, 1000, 3, [-100, 100], [0, 0]]
        self.widget.map.redraw_markers_overlay_image(*args, new_image=True)
        # Force non-JS overlay redrawing
        self.widget.map.N_POINTS_PER_ITER = 5
        self.widget.map.redraw_markers_overlay_image(*args, new_image=True)
        # pylint: disable=protected-access
        assert (not np.isnan(self.widget.map._image_token)
                and self.widget.map._image_token is not None)
        self.process_events(until=lambda: self.widget.map._image_token is None)

        self.widget.map.bridge.fit_to_bounds()
        self.widget.map.bridge.selected_area(10, 20, 10, 20)
        self.widget.map.bridge.recompute_heatmap(np.random.random((30, 2)))
        self.widget.map.bridge.redraw_markers_overlay_image(
            1, 2, 3, 4, 5, 6, 7, [1, 2], [3, 4])

        self.widget.clear()
Exemple #5
0
 def test_input_learner_that_does_not_support_sample_weights(self):
     self.send_signal("Learner", KNNLearner())
     self.assertNotIsInstance(self.widget.base_estimator, KNNLearner)
     self.assertIsNone(self.widget.base_estimator)
     self.assertTrue(self.widget.Error.no_weight_support.is_shown())
 def test_inputs(self):
     self.send_signal(self.widget.Inputs.data, self.data)
     self.send_signal(self.widget.Inputs.learner, KNNLearner())
     self.widget.handleNewSignals()
     self.assertEqual(self.widget.map.lat_attr, self.data.domain[0])
Exemple #7
0
 def test_classification(self):
     sf = StackedFitter([TreeLearner(), KNNLearner()])
     results = CrossValidation(self.iris, [sf], k=3)
     ca = CA(results)
     self.assertGreater(ca, 0.9)