Skip to content

Instantly share code, notes, and snippets.

Avatar

Mathieu Blondel mblondel

View GitHub Profile
@mblondel
mblondel / kernel_kmeans.py
Last active March 18, 2023 15:52
Kernel K-means.
View kernel_kmeans.py
"""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 / hmm.tex
Created July 12, 2010 14:42
Good-looking HMM and Lattice diagrams using TikZ
View hmm.tex
% (C) Mathieu Blondel, July 2010
\documentclass[a4paper,10pt]{article}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{lmodern}
\usepackage{amsmath}
@mblondel
mblondel / projection_simplex.py
Last active March 16, 2023 22:06
Projection onto the simplex
View projection_simplex.py
"""
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 / multiclass_svm.py
Last active March 3, 2023 07:57
Multiclass SVMs
View multiclass_svm.py
"""
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 / letor_metrics.py
Last active February 2, 2023 07:37
Learning to rank metrics.
View letor_metrics.py
# (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 / statistical_tests.py
Last active January 26, 2023 14:14
t-test and wilcoxon-test examples in Python
View statistical_tests.py
# Mathieu Blondel, February 2012
# License: BSD 3 clause
# Port to Python of examples in chapter 5 of
# "Introductory Statistics with R" by Peter Dalgaard
import numpy as np
from scipy.stats import ttest_1samp, wilcoxon, ttest_ind, mannwhitneyu
# daily intake of energy in kJ for 11 women
@mblondel
mblondel / xref.txt
Created May 10, 2013 09:43
Cross-referencing in LaTeX.
View xref.txt
paper.tex: main manuscript
supp.tex: supplementary material
Cross-referencing
-----------------
We want to cross-reference equations in paper.tex from supp.tex.
@mblondel
mblondel / kmeans.py
Last active November 21, 2022 16:22
Fuzzy K-means and K-medians
View kmeans.py
# Copyright Mathieu Blondel December 2011
# License: BSD 3 clause
import numpy as np
import pylab as pl
from sklearn.base import BaseEstimator
from sklearn.utils import check_random_state
from sklearn.cluster import MiniBatchKMeans
from sklearn.cluster import KMeans as KMeansGood
@mblondel
mblondel / kernel_sgd.py
Last active November 15, 2022 17:40
Kernel SGD
View kernel_sgd.py
# Mathieu Blondel, May 2012
# License: BSD 3 clause
import numpy as np
def euclidean_distances(X, Y=None, Y_norm_squared=None, squared=False):
XX = np.sum(X * X, axis=1)[:, np.newaxis]
YY = np.sum(Y ** 2, axis=1)[np.newaxis, :]
distances = np.dot(X, Y.T)
distances *= -2
@mblondel
mblondel / lda_gibbs.py
Last active October 24, 2022 15:48
Latent Dirichlet Allocation with Gibbs sampler
View lda_gibbs.py
"""
(C) Mathieu Blondel - 2010
License: BSD 3 clause
Implementation of the collapsed Gibbs sampler for
Latent Dirichlet Allocation, as described in
Finding scientifc topics (Griffiths and Steyvers)
"""