Skip to content

Instantly share code, notes, and snippets.

View MaxHalford's full-sized avatar

Max Halford MaxHalford

View GitHub Profile
@MaxHalford
MaxHalford / callback.py
Created May 24, 2018 15:20
Keras eval callback
import keras
class EvalCallback(keras.callbacks.Callback):
def __init__(self, X_val, y_val, metric):
super().__init__()
self.X_val = X_val
self.y_val = y_val
self.metric = metric
@MaxHalford
MaxHalford / reverse.py
Created June 19, 2018 19:37
Reverse engineer one-hot encoded categorical variable
import collections
import itertools
df = pd.DataFrame({
'a': [1, 0, 0, 0],
'b': [0, 1, 0, 0],
'c': [0, 0, 1, 0],
'd': [0, 0, 0, 1],
'e': [1, 1, 0, 0],
@MaxHalford
MaxHalford / fit.py
Created August 6, 2018 09:25
Keras CNN blueprint
import glob
import imageio
from keras import layers
from keras import losses
from keras import models
from keras import optimizers
import numpy as np
import pandas as pd
@MaxHalford
MaxHalford / rpi.py
Last active March 1, 2019 15:36
NCAA rating formulas
"""
Rating percentage index (RPI).
Example taken from https://www.wikiwand.com/en/Rating_percentage_index#/Basketball_formula
"""
X = pd.DataFrame(
data=[
(2010, 'UConn', 64, 'Kansas', 57),
(2010, 'UConn', 82, 'Duke', 68),
@MaxHalford
MaxHalford / lgbm_tree_outputs.py
Created October 15, 2019 08:37
LightGBM tree outputs
import lightgbm as lgb
from sklearn import datasets
from sklearn import model_selection
X, y = datasets.load_boston(return_X_y=True)
X_fit, X_val, y_fit, y_val
model = lgb.LGBMRegressor()
model.fit(X_fit, y_fit)
@MaxHalford
MaxHalford / Sampling.ipynb
Created December 19, 2019 21:16
Over/under/hybrid sampling a stream
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@MaxHalford
MaxHalford / multi.py
Last active February 28, 2020 10:36
Find count(s) from percentage(s)
import numpy as np
goal_fracs = np.array([.1, .9])
goal_fracs = np.array([.04, .04, .11, .14, .67])
counts = np.zeros_like(goal_fracs)
n = 1
tol = .001
a = 0
@MaxHalford
MaxHalford / mean.py
Last active March 25, 2020 11:09
creme mean
>>> from creme import stats
>>> mean = stats.Mean()
>>> mean.update(5)
>>> mean.update(10)
>>> mean
7.5
>>> mean.update(6)
@MaxHalford
MaxHalford / target_agg.py
Created March 25, 2020 11:10
creme target encoding
>>> from creme import feature_extraction
>>> from creme import stats
>>> X = [
... {'place': 'Taco Bell', 'revenue': 42},
... {'place': 'Burger King', 'revenue': 16},
... {'place': 'Burger King', 'revenue': 24},
... {'place': 'Taco Bell', 'revenue': 58},
... {'place': 'Burger King', 'revenue': 20},
... {'place': 'Taco Bell', 'revenue': 50}