Skip to content

Commit

Permalink
Further cleanups to benchmark script.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajtulloch committed Mar 8, 2014
1 parent 6827311 commit a3dba48
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
19 changes: 8 additions & 11 deletions benchmarks/bench_isotonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,38 @@
import numpy as np
import gc
from datetime import datetime
from sklearn.isotonic import IsotonicRegression
from sklearn.isotonic import isotonic_regression
from sklearn.utils.bench import total_seconds
import matplotlib.pyplot as plt
import argparse


def generate_perturbed_logarithm_dataset(size):
X = np.arange(n)
Y = np.random.randint(-50, 50, size=(n,)) \
return np.random.randint(-50, 50, size=n) \
+ 50. * np.log(1 + np.arange(n))
return (X, Y)


def generate_logistic_dataset(size):
X = np.sort(np.random.normal(size=size))
Y = np.random.random(size=size) < 1.0 / (1.0 + np.exp(-X))
return (X, Y)
return Y


DATASET_GENERATORS = {
'peturbed_logarithm': generate_perturbed_logarithm_dataset,
'perturbed_logarithm': generate_perturbed_logarithm_dataset,
'logistic': generate_logistic_dataset
}


def bench_isotonic_regression(X, Y):
def bench_isotonic_regression(Y):
"""
Runs a single iteration of isotonic regression on the input data,
and reports the total time taken (in seconds).
"""
gc.collect()

tstart = datetime.now()
clf = IsotonicRegression()
clf.fit(X, Y)
isotonic_regression(Y)
delta = datetime.now() - tstart
return total_seconds(delta)

Expand Down Expand Up @@ -77,9 +74,9 @@ def bench_isotonic_regression(X, Y):

# Generate a synthetic dataset used in the unit tests for
# isotonic regression.
X, Y = DATASET_GENERATORS[args.dataset](n)
Y = DATASET_GENERATORS[args.dataset](n)
time_per_iteration = \
[bench_isotonic_regression(X, Y) for i in range(args.iterations)]
[bench_isotonic_regression(Y) for i in range(args.iterations)]
timing = (n, np.mean(time_per_iteration))
timings.append(timing)

Expand Down
2 changes: 1 addition & 1 deletion sklearn/_isotonic.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a3dba48

Please sign in to comment.