Skip to content

Instantly share code, notes, and snippets.

@MaxHalford
MaxHalford / linear-models.ipynb
Created June 9, 2020 17:33
creme mini-batch performance
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@MaxHalford
MaxHalford / inspect.py
Created July 17, 2020 08:42
sklearn partial_fit support
import importlib
import inspect
def worthy(obj):
return inspect.isclass(obj) and hasattr(obj, 'partial_fit')
for _, submodule in inspect.getmembers(importlib.import_module('sklearn'), inspect.ismodule):
for _, obj in inspect.getmembers(submodule, worthy):
print(submodule.__name__, obj.__name__)
@MaxHalford
MaxHalford / med_filter.pyx
Created August 23, 2020 08:07
Median filter in Cython
import numpy as np
cimport cython
cimport numpy as np
ctypedef np.uint_t uint
ctypedef np.uint8_t uint8
@cython.boundscheck(False)
@MaxHalford
MaxHalford / iter_batches.py
Created September 23, 2020 14:35
Streaming recipes
import pandas as pd
def iter_batches(X_y, batch_size):
x_batch = [None] * batch_size
y_batch = [None] * batch_size
j = 0
for i, (x, y) in enumerate(X_y, start=1):
@MaxHalford
MaxHalford / rules.py
Created December 6, 2020 12:04
Rule-based system
import abc
class Rule(abc.ABC):
def __init__(self, var_name):
self.var_name = var_name
@abc.abstractmethod
def __repr__(self):
"""String representation of the Python expression."""
@MaxHalford
MaxHalford / tree.py
Created January 5, 2021 14:52
Tree implementation
"""Generic branch and leaf implementation."""
import operator
import textwrap
import typing
class Op:
"""An operator that is part of a split."""
__slots__ = "symbol", "func"
@MaxHalford
MaxHalford / poisson.py
Created January 27, 2021 18:29
Pure Python random laws
import math
import random
def poisson(l, rng=random):
"""From https://www.johndcook.com/blog/2010/06/14/generating-poisson-random-values/"""
L = math.exp(-l)
k = 0
p = 1
@MaxHalford
MaxHalford / abbyy.py
Created February 16, 2021 10:02
ABBYY synchronous query
import urllib.parse
import requests
import time
import xml.dom.minidom
def get_abbyy_transcription(doc, app, password):
proxies = {}
url_params = {
@MaxHalford
MaxHalford / merge.py
Created June 15, 2022 17:21
Group by merge
import itertools
def merge_components(cs):
while True:
for (i, a), (j, b) in itertools.combinations(enumerate(cs), 2):
if a[0] == b[0]:
a[1].extend(b[1])
del cs[j]
break
else:
<!DOCTYPE html>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<div id="app">
<div class="grid-container">
<button class="grid-item" v-for="key in keys" @click="click(key[0], key[1])">
{{ key[2] }}
</button>
</div>