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 / 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)
@fabianp
fabianp / gist:1076844
Last active September 26, 2015 09:37
Ridge coefficients as a function of the regularization parameter
"""
Ridge coefficients as a function of the regularization parameter
----------------------------------------------------------------
And highlight in dashed lines the optimal value by cross-validation.
Author: Fabian Pedregosa -- <fabian@fseoane.net>
"""
print __doc__
@fabianp
fabianp / chkfinite.pyx
Created July 19, 2011 18:55
check an array for finite values
cimport numpy as np
import numpy as np
np.import_array()
def chkfinite_double(np.ndarray X):
cdef int i, length
cdef np.PyArrayObject val
cdef np.flatiter iter
@fabianp
fabianp / plot_memory.py
Created October 14, 2011 13:52
Plot memory usage of qr_multiply using numpy and scipy
"""
Plot memory usage of a numeric computation using numpy and scipy
"""
"""Get process information"""
import time, sys, os
import linecache
if sys.platform.startswith('linux'):
@fabianp
fabianp / simple_client.py
Created October 15, 2011 08:44
Download torrent files in sequential order
"""
usage : simple_client.py torrent_file
"""
#!/usr/bin/env python
# Copyright Arvid Norberg 2008. Use, modification and distribution is
# subject to the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
# with modifications by Fabian Pedregosa <fabian@fseoane.net>
# October 2011
@fabianp
fabianp / gist:1322711
Created October 28, 2011 16:37
Ridge benchmark
def _solve(A, b, solver, tol):
# helper method for ridge_regression, A is symmetric positive
if solver == 'auto':
if hasattr(A, 'todense'):
solver = 'sparse_cg'
else:
solver = 'dense_cholesky'
if solver == 'sparse_cg':
@fabianp
fabianp / gist:1342033
Created November 5, 2011 21:18
Low rank approximation for the lena image
"""
Low rank approximation for the lena image
"""
import numpy as np
import scipy as sp
from scipy import linalg
import pylab as pl
X = sp.lena().astype(np.float)
pl.gray()
@fabianp
fabianp / group_lasso.py
Created December 2, 2011 14:17
group lasso
import numpy as np
from scipy import linalg, optimize
MAX_ITER = 100
def group_lasso(X, y, alpha, groups, max_iter=MAX_ITER, rtol=1e-6,
verbose=False):
"""
Linear least-squares with l2/l1 regularization solver.
@fabianp
fabianp / nullclient.c
Created February 24, 2012 22:48
nullclient from libpurple
/*
* pidgin
*
* Pidgin is the legal property of its developers, whose names are too numerous
* to list here. Please refer to the COPYRIGHT file distributed with this
* source distribution.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@fabianp
fabianp / ranking.py
Last active February 1, 2024 10:02
Pairwise ranking using scikit-learn LinearSVC
"""
Implementation of pairwise ranking using scikit-learn LinearSVC
Reference:
"Large Margin Rank Boundaries for Ordinal Regression", R. Herbrich,
T. Graepel, K. Obermayer 1999
"Learning to rank from medical imaging data." Pedregosa, Fabian, et al.,
Machine Learning in Medical Imaging 2012.