Beispiel #1
0
    def test_linear_regression_weights_on(self, dataset):
        predictor = self.LEARNER(dataset)
        weights = get_linear_svm_weights(predictor)

        for inst in dataset[:20]:
            t_inst = Orange.data.Instance(predictor.domain, inst)
            prediction = predictor(inst)
            w_sum = example_weighted_sum(t_inst, weights)
            self.assertAlmostEqual(float(prediction), w_sum - predictor.rho[0], places=4)
Beispiel #2
0
    def test_linear_classifier_weights_on(self, dataset):
        # Test get_linear_svm_weights
        classifier = self.LEARNER(dataset)
        weights = get_linear_svm_weights(classifier, sum=True)

        weights = get_linear_svm_weights(classifier, sum=False)

        n_class = len(classifier.class_var.values)

        def class_pairs(n_class):
            for i in range(n_class - 1):
                for j in range(i + 1, n_class):
                    yield i, j

        l_map = classifier._get_libsvm_labels_map()

        for inst in dataset[:20]:
            dec_values = classifier.get_decision_values(inst)

            for dec_v, weight, rho, pair in zip(dec_values, weights, classifier.rho, class_pairs(n_class)):
                t_inst = Orange.data.Instance(classifier.domain, inst)
                dec_v1 = example_weighted_sum(t_inst, weight) - rho
                self.assertAlmostEqual(dec_v, dec_v1, 4)