From 60f72c91f7bc701a705965af5de925ba7effefcf Mon Sep 17 00:00:00 2001
From: Fabian Pedregosa <fabian.pedregosa@inria.fr>
Date: Thu, 18 Nov 2010 10:36:05 +0100
Subject: [PATCH] Rename predict_margin --> decision_function.

---
 examples/svm/plot_oneclass.py       | 2 +-
 scikits/learn/sgd/base.py           | 4 ++--
 scikits/learn/sgd/sgd.py            | 2 +-
 scikits/learn/sgd/sparse/sgd.py     | 2 +-
 scikits/learn/sgd/tests/test_sgd.py | 4 ++--
 scikits/learn/svm/base.py           | 2 +-
 scikits/learn/svm/libsvm.py         | 2 +-
 scikits/learn/svm/tests/test_svm.py | 8 ++++----
 8 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/examples/svm/plot_oneclass.py b/examples/svm/plot_oneclass.py
index fb1f397a55..89ac5dbd13 100644
--- a/examples/svm/plot_oneclass.py
+++ b/examples/svm/plot_oneclass.py
@@ -24,7 +24,7 @@ clf = svm.OneClassSVM(nu=0.1, kernel="rbf", gamma=0.1)
 clf.fit(X)
 
 # plot the line, the points, and the nearest vectors to the plane
-Z = clf.predict_margin(np.c_[xx.ravel(), yy.ravel()])
+Z = clf.decision_function(np.c_[xx.ravel(), yy.ravel()])
 Z = Z.reshape(xx.shape)
 y_pred = clf.predict(X)
 
diff --git a/scikits/learn/sgd/base.py b/scikits/learn/sgd/base.py
index 65c4940f39..3e2576819b 100644
--- a/scikits/learn/sgd/base.py
+++ b/scikits/learn/sgd/base.py
@@ -68,7 +68,7 @@ class BaseSGD(BaseEstimator, ClassifierMixin):
         array, shape = [n_samples]
            Array containing the predicted class labels.
         """
-        scores = self.predict_margin(X)
+        scores = self.decision_function(X)
         if self.classes.shape[0] == 2:
             indices = np.array(scores > 0, dtype=np.int)
         else:
@@ -91,7 +91,7 @@ class BaseSGD(BaseEstimator, ClassifierMixin):
         """
         if (isinstance(self.loss_function, Log) and
             self.classes.shape[0] == 2):
-            return 1.0 / (1.0 + np.exp(-self.predict_margin(X)))
+            return 1.0 / (1.0 + np.exp(-self.decision_function(X)))
         else:
             raise NotImplementedError("%s loss does not provide "
                                       "this functionality" % self.loss)
diff --git a/scikits/learn/sgd/sgd.py b/scikits/learn/sgd/sgd.py
index 5b36253563..1903c6528e 100644
--- a/scikits/learn/sgd/sgd.py
+++ b/scikits/learn/sgd/sgd.py
@@ -210,7 +210,7 @@ class SGD(BaseSGD):
             self.coef_[i] = coef
             self.intercept_[i] = intercept
 
-    def predict_margin(self, X):
+    def decision_function(self, X):
         """Predict signed 'distance' to the hyperplane (aka confidence score)
 
         Parameters
diff --git a/scikits/learn/sgd/sparse/sgd.py b/scikits/learn/sgd/sparse/sgd.py
index ba5b502f61..cf570aaeb6 100644
--- a/scikits/learn/sgd/sparse/sgd.py
+++ b/scikits/learn/sgd/sparse/sgd.py
@@ -234,7 +234,7 @@ class SGD(BaseSGD):
         self._set_coef(self.coef_)
         self.intercept_ = self.intercept_
 
-    def predict_margin(self, X):
+    def decision_function(self, X):
         """Predict signed 'distance' to the hyperplane (aka confidence score).
 
         Parameters
diff --git a/scikits/learn/sgd/tests/test_sgd.py b/scikits/learn/sgd/tests/test_sgd.py
index b83bd39ce1..60652d6f99 100644
--- a/scikits/learn/sgd/tests/test_sgd.py
+++ b/scikits/learn/sgd/tests/test_sgd.py
@@ -117,7 +117,7 @@ class DenseSGDTestCase(unittest.TestCase):
         clf = self.factory(alpha=0.01, n_iter=20).fit(X2, Y2)
         assert clf.coef_.shape == (3, 2)
         assert clf.intercept_.shape == (3,)
-        assert clf.predict_margin([0, 0]).shape == (1, 3)
+        assert clf.decision_function([0, 0]).shape == (1, 3)
         pred = clf.predict(T2)
         assert_array_equal(pred, true_result2)
 
@@ -136,7 +136,7 @@ class DenseSGDTestCase(unittest.TestCase):
         clf = self.factory(alpha=0.01, n_iter=20, n_jobs=2).fit(X2, Y2)
         assert clf.coef_.shape == (3, 2)
         assert clf.intercept_.shape == (3,)
-        assert clf.predict_margin([0, 0]).shape == (1, 3)
+        assert clf.decision_function([0, 0]).shape == (1, 3)
         pred = clf.predict(T2)
         assert_array_equal(pred, true_result2)
 
diff --git a/scikits/learn/svm/base.py b/scikits/learn/svm/base.py
index 62e660b20b..5240b61114 100644
--- a/scikits/learn/svm/base.py
+++ b/scikits/learn/svm/base.py
@@ -207,7 +207,7 @@ class BaseLibSVM(BaseEstimator):
                       self.probA_, self.probB_)
         return pprob[:, np.argsort(self.label_)]
 
-    def predict_margin(self, T):
+    def decision_function(self, T):
         """
         Calculate the distance of the samples in T to the separating hyperplane.
 
diff --git a/scikits/learn/svm/libsvm.py b/scikits/learn/svm/libsvm.py
index c3c0b112b8..bb88292e1b 100644
--- a/scikits/learn/svm/libsvm.py
+++ b/scikits/learn/svm/libsvm.py
@@ -169,7 +169,7 @@ class NuSVC(BaseLibSVM, ClassifierMixin):
     predict_proba(X) : array
         Return probability estimates.
 
-    predict_margin(X) : array
+    decision_function(X) : array
         Return distance to predicted margin.
 
     Examples
diff --git a/scikits/learn/svm/tests/test_svm.py b/scikits/learn/svm/tests/test_svm.py
index 5612048826..6c230810e4 100644
--- a/scikits/learn/svm/tests/test_svm.py
+++ b/scikits/learn/svm/tests/test_svm.py
@@ -205,7 +205,7 @@ def test_probability():
 
 # def test_margin():
 #     """
-#     Test predict_margin
+#     Test decision_function
 
 #     We create a set of points lying in two lines, so that margin is easily
 #     calculated in a linear kernel.
@@ -217,15 +217,15 @@ def test_probability():
 #     Y = [0]*10 + [1]*10
 #     T = [[1]]*10 + [[-1]]*10
 #     clf = svm.SVC(kernel='linear').fit(X, Y)
-#     assert_array_almost_equal(clf.predict_margin(X), T)
+#     assert_array_almost_equal(clf.decision_function(X), T)
 
 #     # the same using a callable kernel
 #     kfunc = lambda x, y: np.dot(x, y.T)
 #     clf = svm.SVC(kernel=kfunc).fit(X, Y)
-#     assert_array_almost_equal(clf.predict_margin(X), T)
+#     assert_array_almost_equal(clf.decision_function(X), T)
 
 #     # failing test
-#     # assert_array_almost_equal (clf.predict_margin(iris.data),
+#     # assert_array_almost_equal (clf.decision_function(iris.data),
 #     #                            np.dot(clf.coef_.T, iris.data) + \
 #     #                            clf.intercept_)
 
-- 
GitLab