Skip to content

Instantly share code, notes, and snippets.

View fabianp's full-sized avatar
🏠
Working from home

Fabian Pedregosa fabianp

🏠
Working from home
View GitHub Profile
@fabianp
fabianp / lowess.py
Last active August 29, 2015 13:58
SParse Additive Models (SPAM) in Python
"""
This module implements the Lowess function for nonparametric regression.
Functions:
lowess Fit a smooth nonparametric regression curve to a scatterplot.
For more information, see
William S. Cleveland: "Robust locally weighted regression and smoothing
scatterplots", Journal of the American Statistical Association, December 1979,
@fabianp
fabianp / gist:804e8a2891633d4618dd
Created September 9, 2014 13:41
profile strong rules
=====================
Lasso and Elastic Net
=====================
Lasso and elastic net (L1 and L2 penalisation) implemented using a
coordinate descent.
The coefficients can be forced to be positive.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fabianp
fabianp / bench_triangular_solve.py
Created October 29, 2010 21:05
Benchmark solve_triangular from scipy.linalg
import numpy as np
from scipy import linalg
from datetime import datetime
import gc
mu_sec = 1e-6 # number of seconds in one microseconds
solve_time =[]
solve_triangular_time =[]
@fabianp
fabianp / gist:820401
Created February 10, 2011 11:52
Some experiments with PLS
"""
Just some experiments with pls
"""
import numpy as np
m, n = 3, 3
X = np.random.randn(m, n)
Y = np.random.randn(m, n)
@fabianp
fabianp / gist:905457
Created April 6, 2011 10:37
Print error distribution for norm
import pylab as pl
import numpy as np
import scipy.linalg
nrm2, = scipy.linalg.get_blas_funcs(('nrm2',), np.empty(0, dtype=np.float32))
x_min, x_max = -4., 0
y_min, y_max = 0, 4.
h = 134567e-7
@fabianp
fabianp / gist:927229
Created April 19, 2011 12:08
GridSearch fails when arguments are not hashable
import numpy as np
from scikits.learn import svm, grid_search, datasets
iris = datasets.load_iris()
parameters = {'C': [np.array(1)]}
svr = svm.SVC()
clf = grid_search.GridSearchCV(svr, parameters)
clf.fit(iris.data, iris.target)
print clf.grid_points_scores_
@fabianp
fabianp / plot_lle_digits.py
Created May 4, 2011 05:56
Handwritten digits and Locally Linear Embedding
"""
===============================================
Handwritten digits and Locally Linear Embedding
===============================================
An illustration of locally linear embedding on the digits dataset.
"""
# Author: Fabian Pedregosa -- <fabian.pedregosa@inria.fr>
# License: BSD, (C) INRIA 2011
@fabianp
fabianp / gist:1073728
Created July 9, 2011 16:43
Classical Gram-Schmidt algorithm
import numpy as np
from scipy import linalg
def cgs(A):
"""Classical Gram-Schmidt (CGS) algorithm"""
m, n = A.shape
R = np.zeros((n, n))
Q = np.empty((m, n))
R[0, 0] = linalg.norm(A[:, 0])
Q[:, 0] = A[:, 0] / R[0, 0]
@fabianp
fabianp / gist:1076792
Created July 11, 2011 21:04
Ridge regression
import numpy as np
from scipy import linalg
def ridge(A, b, alphas):
"""Return coefficients for regularized least squares
||A x - b|| + alpha ||x||
"""
U, s, V = linalg.svd(X, full_matrices=False)
d = np.dot(U.T, y) / (s + alphas[:, np.newaxis] / s)
return np.dot(d, V)