Skip to content

Instantly share code, notes, and snippets.

View searope's full-sized avatar

Sea Rope searope

View GitHub Profile
@searope
searope / dictionary_values_permutations.py
Created May 17, 2022 14:41
permutates all elements in list values of a dictionary to return a dictionary with the same keys but single values
import itertools
my_dict = {'A':['D','E'],'B':['F','G','H'],'C':['I','J']}
keys, values = zip(*my_dict.items())
permutations_dicts = [dict(zip(keys, v)) for v in itertools.product(*values)]
# this will provide you a list of dicts with the permutations:
print(permutations_dicts)
#[{'A':'D', 'B':'F', 'C':'I'},
@searope
searope / multiprocessing.py
Last active May 17, 2022 16:57
Multiprocessing in Python with Multprocessing module
import random
import time
import multiprocessing as mp
import itertools as it
# just an example generator to prove lazy access by printing when it generates
def get_counter(limit=10):
for i in range(limit):
for j in range(limit):
print(f"YIELDED: {i},{j}")
@searope
searope / FuncScorer.py
Last active June 7, 2022 03:52
helper class to make custom mentrics easier in sklearn
import numpy as np
from sklearn.preprocessing import QuantileTransformer
from sklearn.metrics._scorer import _BaseScorer
class FuncScorer(_BaseScorer):
def _score(self, method_caller, estimator, X, y_true, sample_weight=None):
"""Evaluate predicted target values for X relative to y_true.