Skip to content

Instantly share code, notes, and snippets.

View mblondel's full-sized avatar

Mathieu Blondel mblondel

View GitHub Profile
@mblondel
mblondel / multiclass_svm.py
Last active March 3, 2023 07:57
Multiclass SVMs
"""
Multiclass SVMs (Crammer-Singer formulation).
A pure Python re-implementation of:
Large-scale Multiclass Support Vector Machine Training via Euclidean Projection onto the Simplex.
Mathieu Blondel, Akinori Fujino, and Naonori Ueda.
ICPR 2014.
http://www.mblondel.org/publications/mblondel-icpr2014.pdf
"""
@mblondel
mblondel / projection_simplex.py
Last active March 11, 2024 12:07
Projection onto the simplex
"""
License: BSD
Author: Mathieu Blondel
Implements three algorithms for projecting a vector onto the simplex: sort, pivot and bisection.
For details and references, see the following paper:
Large-scale Multiclass Support Vector Machine Training via Euclidean Projection onto the Simplex
Mathieu Blondel, Akinori Fujino, and Naonori Ueda.
@mblondel
mblondel / out_of_scope.py
Last active January 18, 2018 14:13
Out of scope
def test():
print(i)
i = 1
test()
@mblondel
mblondel / nmf_cd.py
Last active June 12, 2019 20:00
NMF by coordinate descent
"""
NMF by coordinate descent, designed for sparse data (without missing values)
"""
# Author: Mathieu Blondel <mathieu@mblondel.org>
# License: BSD 3 clause
import numpy as np
import scipy.sparse as sp
import numba
@mblondel
mblondel / local_regression.py
Last active August 29, 2015 14:02
Local regression
"""Local regression"""
# Author: Mathieu Blondel <mathieu@mblondel.org>
# License: BSD 3 clause
import numpy as np
from sklearn.base import BaseEstimator, RegressorMixin
from sklearn.metrics.pairwise import pairwise_kernels
from sklearn.linear_model import Ridge
@mblondel
mblondel / letor_metrics.py
Last active April 24, 2024 19:43
Learning to rank metrics.
# (C) Mathieu Blondel, November 2013
# License: BSD 3 clause
import numpy as np
def ranking_precision_score(y_true, y_score, k=10):
"""Precision at rank k
Parameters
@mblondel
mblondel / matrix_sketch.py
Last active February 13, 2019 09:26
Frequent directions algorithm for matrix sketching.
# (C) Mathieu Blondel, November 2013
# License: BSD 3 clause
import numpy as np
from scipy.linalg import svd
def frequent_directions(A, ell, verbose=False):
"""
Return the sketch of matrix A.
@mblondel
mblondel / curve_averaging.py
Last active May 13, 2017 16:47
Variable-length curve averaging
"""Variable-length curve averaging"""
# Author: Mathieu Blondel <mathieu@mblondel.org>
# License: BSD 3 clause
import numpy as np
from scipy.interpolate import interp1d
def curves_mean_std(X, Y, kind="linear"):
@mblondel
mblondel / kernel_kmeans.py
Last active January 4, 2024 11:45
Kernel K-means.
"""Kernel K-means"""
# Author: Mathieu Blondel <mathieu@mblondel.org>
# License: BSD 3 clause
import numpy as np
from sklearn.base import BaseEstimator, ClusterMixin
from sklearn.metrics.pairwise import pairwise_kernels
from sklearn.utils import check_random_state
@mblondel
mblondel / gaussian_process.py
Created August 14, 2013 12:52
Gaussian Process Regression
"""Gaussian processes"""
# Author: Mathieu Blondel <mathieu@mblondel.org>
# License: BSD 3 clause
import numpy as np
from scipy.linalg import cholesky, solve_triangular
from sklearn.base import BaseEstimator, RegressorMixin
from sklearn.metrics.pairwise import pairwise_kernels