Skip to content

Instantly share code, notes, and snippets.

Mathieu Blondel mblondel

Block or report user

Report or block mblondel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mblondel
mblondel / perceptron.py
Last active Aug 7, 2019
Kernel Perceptron
View perceptron.py
# Mathieu Blondel, October 2010
# License: BSD 3 clause
import numpy as np
from numpy import linalg
def linear_kernel(x1, x2):
return np.dot(x1, x2)
def polynomial_kernel(x, y, p=3):
@mblondel
mblondel / regression_lp.py
Last active Sep 25, 2015
Linear regression by Linear Programming
View regression_lp.py
# (C) 2011 Mathieu Blondel
# License: BSD 3 clause
import numpy as np
import numpy.linalg as linalg
import pylab as pl
from cvxopt import matrix, solvers
np.random.seed(0)
@mblondel
mblondel / online_variance.py
Created Aug 2, 2011
Sample variance in a single pass
View online_variance.py
def online_mean_variance(iterable):
mN = 0
mM = 0.0
mS = 0.0
for x in iterable:
mN += 1
nextM = mM + (x - mM) / mN
mS += (x - mM) * (x - nextM)
@mblondel
mblondel / kmeans.py
Last active Sep 25, 2019
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 / statistical_tests.py
Last active Oct 19, 2019
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
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 / lbfgs_nnls.py
Last active Dec 10, 2015
NNLS via LBFGS
View lbfgs_nnls.py
# (C) Mathieu Blondel 2012
# License: BSD 3 clause
import numpy as np
from scipy.optimize import fmin_l_bfgs_b
from sklearn.base import BaseEstimator, RegressorMixin
from sklearn.utils.extmath import safe_sparse_dot
@mblondel
mblondel / xref.txt
Created May 10, 2013
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 / imputer.py
Last active May 13, 2017
Missing-value imputation
View imputer.py
# (C) Mathieu Blondel
# License: BSD 3 clause
import numpy as np
from numpy import ma
import scipy.sparse as sp
def _get_mask(X, missing_values, sparse=False):
if sparse:
@mblondel
mblondel / sparse_multiclass_numba.py
Last active Sep 19, 2018
Sparse Multiclass Classification in Numba!
View sparse_multiclass_numba.py
"""
(C) August 2013, Mathieu Blondel
# License: BSD 3 clause
This is a Numba-based reimplementation of the block coordinate descent solver
(without line search) described in the paper:
Block Coordinate Descent Algorithms for Large-scale Sparse Multiclass
Classification. Mathieu Blondel, Kazuhiro Seki, and Kuniaki Uehara.
Machine Learning, May 2013.
You can’t perform that action at this time.