git clone https://gist.github.com/ishu3101/6fb35afd237e42ef25f9
mv 6fb35afd237e42ef25f9 ConvertTo-Markdown
cd ConvertTo-Markdown
| # Author: Vlad Niculae <vlad@vene.ro> | |
| # Makes use of memory_profiler from Fabian Pedregosa | |
| # available at https://github.com/fabianp/memory_profiler | |
| from IPython.core.magic import Magics, line_magic, magics_class | |
| class MemMagics(Magics): | |
| @line_magic | |
| def memit(self, line='', setup='pass'): |
| # 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): |
| # 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) |
| # 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 |
| """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 |
| # 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 |