Пример #1
0
    def test_predictions_shapes(self):
        """
        Test the resulting shapes of probabilities for SGD
        """
        # one where probabilities computed from data
        # hinge loss do not enable predict_proba
        lrn = SGDClassificationLearner()
        mod = lrn(self.iris)
        self.assertTupleEqual((50, 3), mod(self.iris[:50], mod.Probs).shape)
        self.assertTupleEqual((50, ), mod(self.iris[:50], mod.Value).shape)

        # in this case probabilities are retrieved by skl_learner.predict_proba
        lrn = SGDClassificationLearner(loss='modified_huber')
        mod = lrn(self.iris)
        self.assertTupleEqual((50, 3), mod(self.iris[:50], mod.Probs).shape)
        self.assertTupleEqual((50, ), mod(self.iris[:50], mod.Value).shape)
    def test_kernel_explainer_sgd(self):
        learner = SGDClassificationLearner()
        model = learner(self.titanic)
        np.random.shuffle(self.titanic.X)

        shap_values, _, sample_mask, _ = compute_shap_values(
            model, self.titanic[:200], self.titanic[:200])
Пример #3
0
    def test_result_shape(self):
        """
        This test function will be extended for all models in on of the
        following pull requests.
        """
        iris = Table('iris')
        learner = SGDClassificationLearner()

        # model trained on only one value (but three in the domain)
        model = learner(iris)

        res = model(iris[0:50])
        self.assertTupleEqual((50, ), res.shape)

        # probabilities must still be for three classes
        res = model(iris[0:50], model.Probs)
        self.assertTupleEqual((50, 3), res.shape)
Пример #4
0
 def test_coefficients(self):
     lrn = SGDClassificationLearner()
     mod = lrn(self.iris)
     self.assertEqual(len(mod.coefficients[0]), len(mod.domain.attributes))
Пример #5
0
 def test_SGDClassification(self):
     sgd = SGDClassificationLearner()
     cv = CrossValidation(k=3)
     res = cv(self.iris, [sgd])
     self.assertGreater(AUC(res)[0], 0.8)