8000 DOC: use notebook-style in plot_prediction_latency.py by ss-is-master-chief · Pull Request #22418 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions examples/applications/plot_prediction_latency.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def _not_in_sphinx():
return "__file__" in globals()


# %%
# Benchmark and plot helper functions
# -----------------------------------


def atomic_benchmark_estimator(estimator, X_test, verbose=False):
"""Measure runtime prediction of each instance."""
n_instances = X_test.shape[0]
Expand Down Expand Up @@ -289,13 +294,10 @@ def plot_benchmark_throughput(throughputs, configuration):
plt.show()


# #############################################################################
# Main code

start_time = time.time()

# #############################################################################
# %%
# Benchmark bulk/atomic prediction speed for various regressors
# -------------------------------------------------------------

configuration = {
"n_train": int(1e3),
"n_test": int(1e2),
Expand Down Expand Up @@ -325,7 +327,10 @@ def plot_benchmark_throughput(throughputs, configuration):
}
benchmark(configuration)

# benchmark n_features influence on prediction speed
# %%
# Benchmark n_features influence on prediction speed
# --------------------------------------------------

percentile = 90
percentiles = n_feature_influence(
{"ridge": Ridge()},
Expand All @@ -336,9 +341,9 @@ def plot_benchmark_throughput(throughputs, configuration):
)
plot_n_features_influence(percentiles, percentile)

# benchmark throughput
# %%
# Benchmark throughput
# --------------------

throughputs = benchmark_throughputs(configuration)
plot_benchmark_throughput(throughputs, configuration)

stop_time = time.time()
print("example run in %.2fs" % (stop_time - start_time))
0