This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mathieu Blondel, September 2010 | |
# License: BSD 3 clause | |
import numpy as np | |
from numpy import linalg | |
import cvxopt | |
import cvxopt.solvers | |
def linear_kernel(x1, x2): | |
return np.dot(x1, x2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% (C) Mathieu Blondel, July 2010 | |
\documentclass[a4paper,10pt]{article} | |
\usepackage[english]{babel} | |
\usepackage[T1]{fontenc} | |
\usepackage[ansinew]{inputenc} | |
\usepackage{lmodern} | |
\usepackage{amsmath} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Mathieu Blondel | |
# License: BSD 3 clause | |
import numpy as np | |
def projection_simplex(V, z=1, axis=None): | |
""" | |
Projection of x onto the simplex, scaled by z: | |
P(x; z) = argmin_{y >= 0, sum(y) = z} ||y - x||^2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import random | |
""" | |
Find pi by the Monte-Carlo method. | |
area of a circle = pi r^2 | |
area of a square = (2r)^2 = 4 r^2 | |
Perform random uniform sampling between -1 and 1. | |
The proportion of points in the unit circle is: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
NewerOlder