Skip to content

Instantly share code, notes, and snippets.

View pandorica-opens's full-sized avatar

Hanna Kondratiuk pandorica-opens

View GitHub Profile
@pandorica-opens
pandorica-opens / magic_memit.py
Created February 15, 2021 00:54 — forked from vene/magic_memit.py
memit: magic memory usage benching for IPython
# Author: Vlad Niculae <[email protected]>
# 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'):
@pandorica-opens
pandorica-opens / gist_to_github_repo.md
Created October 26, 2020 12:23 — forked from ishu3101/gist_to_github_repo.md
Transfer a gist to a GitHub repository

Transfer a gist to a GitHub repository

clone the gist

git clone https://gist.github.com/ishu3101/6fb35afd237e42ef25f9

rename the directory

mv 6fb35afd237e42ef25f9 ConvertTo-Markdown

change the working directory to the newly renamed directory

cd ConvertTo-Markdown

@pandorica-opens
pandorica-opens / perceptron.py
Created October 15, 2020 17:55 — forked from mblondel/perceptron.py
Kernel Perceptron
# 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):
@pandorica-opens
pandorica-opens / svm.py
Created October 15, 2020 17:55 — forked from mblondel/svm.py
Support Vector Machines
# 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)
@pandorica-opens
pandorica-opens / kernel_sgd.py
Created October 15, 2020 17:50 — forked from mblondel/kernel_sgd.py
Kernel SGD
# 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
@pandorica-opens
pandorica-opens / kernel_kmeans.py
Created October 15, 2020 17:49 — forked from mblondel/kernel_kmeans.py
Kernel K-means.
"""Kernel K-means"""
# Author: Mathieu Blondel <[email protected]>
# 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
@pandorica-opens
pandorica-opens / projection_simplex_vectorized.py
Created October 15, 2020 17:48 — forked from mblondel/projection_simplex_vectorized.py
Vectorized projection onto the simplex
# 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