Skip to content

Instantly share code, notes, and snippets.

@jnothman
Created May 28, 2013 02:58
Show Gist options
  • Select an option

  • Save jnothman/5660263 to your computer and use it in GitHub Desktop.

Select an option

Save jnothman/5660263 to your computer and use it in GitHub Desktop.
from __future__ import print_function
import random
from timeit import timeit
from functools import partial
import numpy as np
from sklearn.preprocessing import LabelEncoder
N_TRIALS = 3
N_SAMPLES = 10000
MULTILABEL = True
for N_CLASSES in range(2, 50):
if MULTILABEL:
classes = np.arange(N_CLASSES)
y_trivial = [random.sample(classes, random.randint(0, N_CLASSES))
for i in range(N_SAMPLES)]
y_lookup = y_trivial[:]
y_lookup[0] = [-1]
else:
y_trivial = np.random.randint(N_CLASSES, size=N_SAMPLES)
y_lookup = y_trivial.copy()
y_lookup[0] = -1
print(N_CLASSES,
*[timeit(partial(LabelEncoder().fit(y).transform, y),
number=N_TRIALS) / N_TRIALS
for y in [y_trivial, y_lookup]], sep='\t')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment