From 9a08fe314c6554c7d544a43cf041e1c583e88152 Mon Sep 17 00:00:00 2001 From: Fabian Pedregosa <fabian.pedregosa@inria.fr> Date: Wed, 16 Jun 2010 10:57:59 +0200 Subject: [PATCH] Cosmetic changes in LAR. --- examples/glm/plot_lar.py | 7 ++++++- scikits/learn/datasets/__init__.py | 2 +- scikits/learn/datasets/base.py | 8 ++++++++ scikits/learn/glm.py | 8 ++++---- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/examples/glm/plot_lar.py b/examples/glm/plot_lar.py index 33ecb6681f..2bbd9a7786 100644 --- a/examples/glm/plot_lar.py +++ b/examples/glm/plot_lar.py @@ -21,6 +21,12 @@ np.random.seed(0) y = np.random.randn(n_samples) X = np.random.randn(n_samples, n_features) +from scikits.learn import datasets + +# diabetes = datasets.load_diabetes() +# X = diabetes.data +# Y = diabetes.target + ################################################################################ # Fit models ################################################################################ @@ -36,7 +42,6 @@ start = datetime.now() clf = glm.LeastAngleRegression().fit(X, y, n_features=7) print "This took ", datetime.now() - start -# alphas = np.append(clf.alphas_, np.zeros(7)) alphas = -np.log10(np.abs(clf.alphas_)) # Display results diff --git a/scikits/learn/datasets/__init__.py b/scikits/learn/datasets/__init__.py index 15bbd36d9f..1e1ca225dd 100644 --- a/scikits/learn/datasets/__init__.py +++ b/scikits/learn/datasets/__init__.py @@ -1 +1 @@ -from base import load_iris, load_digits +from base import load_iris, load_digits, load_diabetes diff --git a/scikits/learn/datasets/base.py b/scikits/learn/datasets/base.py index 4569d9460c..1a943af2c7 100644 --- a/scikits/learn/datasets/base.py +++ b/scikits/learn/datasets/base.py @@ -101,3 +101,11 @@ def load_digits(): images=images, DESCR=fdescr.read()) + + +def load_diabetes(): + data = np.loadtxt(os.path.join(os.path.dirname(__file__) + + '/data/diabetes.csv')) + target = data[:, -1] + data = data[:, :-1] + return Bunch (data=data, target=target) diff --git a/scikits/learn/glm.py b/scikits/learn/glm.py index db73de2239..e13ff66109 100644 --- a/scikits/learn/glm.py +++ b/scikits/learn/glm.py @@ -914,10 +914,10 @@ class LeastAngleRegression (object): from . import minilearn if n_features is None: - n_features = min(X.shape[0], X.shape[1]) + n_features = min(X.shape[0], X.shape[1]) - 1 - sum_k = n_features * (n_features - 1) /2 - self.alphas_ = np.zeros(n_features, dtype=np.float64) + sum_k = n_features * (n_features + 1) /2 + self.alphas_ = np.zeros(n_features + 1, dtype=np.float64) self._cholesky = np.zeros(sum_k, dtype=np.float64) self.beta_ = np.zeros(sum_k , dtype=np.float64) self.row_ = np.zeros(sum_k, dtype=np.int32) @@ -936,6 +936,6 @@ class LeastAngleRegression (object): self.coef_ = sp.coo_matrix((self.beta_, (self.row_, self.col_)), - shape=(X.shape[1], n_features)).todense() + shape=(X.shape[1], n_features + 1)).todense() return self -- GitLab