Skip to content

Instantly share code, notes, and snippets.

View full-sized avatar
🏠
Working from home

Fabian Pedregosa fabianp

🏠
Working from home
View GitHub Profile
@fabianp
fabianp / partial_corr.py
Last active August 27, 2023 17:42
Partial Correlation in Python (clone of Matlab's partialcorr)
View partial_corr.py
"""
Partial Correlation in Python (clone of Matlab's partialcorr)
This uses the linear regression approach to compute the partial
correlation (might be slow for a huge number of variables). The
algorithm is detailed here:
http://en.wikipedia.org/wiki/Partial_correlation#Using_linear_regression
Taking X and Y two variables of interest and Z the matrix with all the variable minus {X, Y},
@fabianp
fabianp / isotonic_regression.py
Created April 23, 2012 09:04
isotonic regression
View isotonic_regression.py
import numpy as np
def isotonic_regression(w, y, x_min=None, x_max=None):
"""
Solve the isotonic regression model:
min Sum w_i (y_i - x_i) ** 2
subject to x_min = x_1 <= x_2 ... <= x_n = x_max
@fabianp
fabianp / frank_wolfe.py
Created March 19, 2018 18:40
Python implementation of the Frank-Wolfe algorithm
View frank_wolfe.py
import numpy as np
from scipy import sparse
# .. for plotting ..
import pylab as plt
# .. to generate a synthetic dataset ..
from sklearn import datasets
n_samples, n_features = 1000, 10000
A, b = datasets.make_regression(n_samples, n_features)
@fabianp
fabianp / gist:934363
Created April 21, 2011 12:16
locally linear embedding - swiss roll example
View gist:934363
# -*- coding: utf-8 -*-
"""
===================================
Swiss Roll reduction with LLE
===================================
An illustration of Swiss Roll reduction
with locally linear embedding
"""
@fabianp
fabianp / ranking.py
Last active June 23, 2022 05:43
Pairwise ranking using scikit-learn LinearSVC
View ranking.py
"""
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.
View jaxopt.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fabianp
fabianp / group_lasso.py
Created December 2, 2011 14:17
group lasso
View group_lasso.py
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.
View flax_resnet_pytorch.py
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
View flax_resnet_groupnorm.py
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@fabianp
fabianp / gist:1342033
Created November 5, 2011 21:18
Low rank approximation for the lena image
View gist:1342033
"""
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()