From 5cb5512384e7f847391f9827c171fd8f1bbcd1a3 Mon Sep 17 00:00:00 2001
From: Michel Vincent <vm.michel@gmail.com>
Date: Wed, 28 Apr 2010 06:51:53 +0000
Subject: [PATCH] Add coef_ to SVR.

git-svn-id: https://scikit-learn.svn.sourceforge.net/svnroot/scikit-learn/trunk@708 22fbfee3-77ab-4535-9bad-27d1bd3bc7d8
---
 scikits/learn/svm.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/scikits/learn/svm.py b/scikits/learn/svm.py
index 606c327355..acb19a9c75 100644
--- a/scikits/learn/svm.py
+++ b/scikits/learn/svm.py
@@ -235,6 +235,20 @@ class SVR(BaseLibsvm):
                          cache_size, eps, C, nr_weight, nu, p,
                          shrinking, probability)
 
+    @property
+    def coef_(self):
+        if _kernel_types[self.kernel] != 'linear':
+            raise NotImplementedError(
+            'coef_ is only available when using a linear kernel')
+        if self.support_.size == 0:
+            raise Exception, 'No support vector'
+
+        coef_ = []
+        for i in range(self.dual_coef_.shape[0]):
+            coef_.append(np.dot(self.dual_coef_[i], self.support_))
+        coef_ = np.array(coef_)
+        return coef_
+
 class OneClassSVM(BaseLibsvm):
     """
     Outlayer detection
-- 
GitLab