Skip to content

Commit

Permalink
remove some style errors in bench code.
Browse files Browse the repository at this point in the history
  • Loading branch information
amueller committed Mar 10, 2015
1 parent 613c3af commit 806cb22
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion benchmarks/bench_multilabel_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _plot(results, metrics, formats, title, x_ticks, x_label,
ap = argparse.ArgumentParser()
ap.add_argument('metrics', nargs='*', default=sorted(METRICS),
help='Specifies metrics to benchmark, defaults to all. '
'Choices are: '.format(sorted(METRICS)))
'Choices are: {}'.format(sorted(METRICS)))
ap.add_argument('--formats', nargs='+', choices=sorted(FORMATS),
help='Specifies multilabel formats to benchmark '
'(defaults to all).')
Expand Down
7 changes: 4 additions & 3 deletions benchmarks/bench_sparsify.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def sparsity_ratio(X):
X = np.random.randn(n_samples, n_features)
inds = np.arange(n_samples)
np.random.shuffle(inds)
X[inds[n_features/1.2:]] = 0 # sparsify input
X[inds[int(n_features / 1.2):]] = 0 # sparsify input
print("input data sparsity: %f" % sparsity_ratio(X))
coef = 3 * np.random.randn(n_features)
inds = np.arange(n_features)
Expand All @@ -81,17 +81,18 @@ def sparsity_ratio(X):
clf.fit(X_train, y_train)
print("model sparsity: %f" % sparsity_ratio(clf.coef_))

@profile

def benchmark_dense_predict():
for _ in range(300):
clf.predict(X_test)

@profile

def benchmark_sparse_predict():
X_test_sparse = csr_matrix(X_test)
for _ in range(300):
clf.predict(X_test_sparse)


def score(y_test, y_pred, case):
r2 = r2_score(y_test, y_pred)
print("r^2 on test data (%s) : %f" % (case, r2))
Expand Down

0 comments on commit 806cb22

Please sign in to comment.