def test_plot_logreg(self): from matplotlib import pyplot as plt temp = get_temp_folder(__file__, "temp_plot_logreg") img = os.path.join(temp, "plot_logreg.png") data = os.path.join(temp, "..", "data", "onnxruntime_LogisticRegression.perf.csv") df = pandas.read_csv(data) ax = plot_bench_results(df, row_cols='N', col_cols='method', x_value='dim', hue_cols='fit_intercept', title="unittest") fig = ax[0, 0].get_figure() fig.savefig(img) if __name__ == "__main__": plt.show() plt.close('all') self.assertExists(img)
def test_plot_polypf(self): from matplotlib import pyplot as plt temp = get_temp_folder(__file__, "temp_plot_polypf") img = os.path.join(temp, "plot_polypf.png") data = os.path.join(temp, "..", "data", "plot_bench_polynomial_features_partial_fit.perf.csv") df = pandas.read_csv(data) ax = plot_bench_results(df, row_cols='N', col_cols=None, x_value='dim', hue_cols=None, cmp_col_values='test', title="unittest") fig = ax[0].get_figure() fig.savefig(img) if __name__ == "__main__": plt.show() plt.close('all') self.assertExists(img)
print(dfi) else: df = pandas.read_csv("%s.perf.csv" % filename) print(df.head()) ############################# # Plot the results # ++++++++++++++++ def label_fct(la): la = la.replace("-lib=", "") la = la.replace("rt=", "-") return la plot_bench_results( df, row_cols=('rt', ), col_cols=('dataset', ), label_fct=label_fct, x_value='N', hue_cols=('lib', ), cmp_col_values='lib', title="Numerical datasets\nBenchmark scikit-learn, xgboost, lightgbm") plt.savefig("%s.curve.png" % filename) import sys if "--quiet" not in sys.argv: plt.show()
'onnxruntime', 'onnx', 'mlprodict'] dfi = pandas.DataFrame(machine_information(pkgs)) dfi.to_csv("%s.time.csv" % filename, index=False) print(dfi) ############################# # Plot the results # ++++++++++++++++ def label_fct(la): la = la.replace("onxpython_compiled", "opy") la = la.replace("onxpython", "opy") la = la.replace("onxonnxruntime1", "ort") la = la.replace("fit_intercept", "fi") la = la.replace("True", "1") la = la.replace("False", "0") la = la.replace("max_depth", "mxd") return la plot_bench_results(df, row_cols=['N', 'max_depth', 'onnx_options'], col_cols='method', x_value='dim', hue_cols=['n_estimators'], title="%s\nBenchmark scikit-learn / onnxruntime" % model_name, label_fct=label_fct) plt.savefig("%s.png" % filename) import sys if "--quiet" not in sys.argv: plt.show()
if has_dask: cluster.close() ######################### # Extract information about the machine used # ++++++++++++++++++++++++++++++++++++++++++ from pymlbenchmark.context import machine_information pkgs = ['numpy', 'pandas', 'sklearn'] dfi = pandas.DataFrame(machine_information(pkgs)) dfi.to_csv("%s.time.csv" % filename, index=False) print(dfi) ############################# # Plot the results # ++++++++++++++++ from pymlbenchmark.plotting import plot_bench_results print(df.columns) plot_bench_results(df, row_cols=['N'], col_cols=['n_jobs'], x_value='dim', hue_cols=['test'], cmp_col_values='test', title="GridSearchCV\nBenchmark caching strategies") import sys if "--quiet" not in sys.argv: plt.show()
def label_fct(la): la = la.replace("onxpython_compiled", "opy") la = la.replace("onxpython", "opy") la = la.replace("onxonnxruntime1", "ort") la = la.replace("fit_intercept", "fi") la = la.replace("True", "1") la = la.replace("False", "0") la = la.replace("max_depth", "mxd") return la from pymlbenchmark.plotting import plot_bench_results plot_bench_results(df, row_cols='N', col_cols='dim', x_value='nbnode', title="%s\nBenchmark scikit-learn / onnxruntime" % "Cascade Add", label_fct=label_fct) plt.savefig("%s.node.png" % filename) ################################## # Plot one ONNX graph # +++++++++++++++++++ for nbnode in (2, 4): onx = generate_onnx_graph(5, nbnode)[0] from onnx.tools.net_drawer import GetPydotGraph, GetOpNodeProducer pydot_graph = GetPydotGraph(onx.graph,
df.to_csv("bench_re2.csv", index=False) print(df.head()) ######################### # Extract information about the machine used # ++++++++++++++++++++++++++++++++++++++++++ from pymlbenchmark.context import machine_information pkgs = ['numpy', 'pandas', 'sklearn'] dfi = pandas.DataFrame(machine_information(pkgs)) print(dfi) ############################# # Plot the results # ++++++++++++++++ from pymlbenchmark.plotting import plot_bench_results print(df.columns) plot_bench_results(df, row_cols=['N'], col_cols=None, x_value='dim', hue_cols=None, cmp_col_values='test', title="re2\nBenchmark re / re2") import matplotlib.pyplot as plt import sys if "--quiet" not in sys.argv: plt.show()
la = la.replace("method=proba", "prob") la = la.replace( "onnx_options={<class 'sklearn.gaussian_process._gpr.GaussianProcessRegressor'>: {'optim': 'cdist'}}", 'cdist') la = la.replace("onnx_options=nan", '-') return la name = "bench_plot_onnxruntime_gpr.perf.csv" df = pandas.read_csv(name) plot_bench_results(df, row_cols=('alpha', 'N'), col_cols='onnx_options', hue_cols='dtype', cmp_col_values=('lib', 'skl'), x_value='dim', y_value='mean', title=None, label_fct=label_fct, ax=None, box_side=4) plt.suptitle( "Acceleration onnxruntime / scikit-learn for GaussianProcessRegressor") plt.savefig("%s.png" % filename) import sys if "--quiet" not in sys.argv: plt.show()
plot_bench_xtime( df[df.norm], col_cols='dataset', hue_cols='model', title= "Numerical datasets - norm=False\nBenchmark scikit-learn / onnxruntime") plt.savefig("%s.normT.time.png" % filename) # plt.show() plot_bench_xtime( df[~df.norm], col_cols='dataset', hue_cols='model', title= "Numerical datasets - norm=False\nBenchmark scikit-learn / onnxruntime") plt.savefig("%s.normF.time.png" % filename) # plt.show() plot_bench_results( df, row_cols='model', col_cols=('dataset', 'norm'), x_value='N', title="Numerical datasets\nBenchmark scikit-learn / onnxruntime") plt.savefig("%s.curve.png" % filename) import sys if "--quiet" not in sys.argv: plt.show()
'onnxruntime', 'onnx', 'mlprodict'] dfi = pandas.DataFrame(machine_information(pkgs)) dfi.to_csv("%s.time.csv" % filename, index=False) print(dfi) ############################# # Plot the results # ++++++++++++++++ def label_fct(la): la = la.replace("onxpython_compiled", "opy") la = la.replace("onxpython", "opy") la = la.replace("onxonnxruntime1", "ort") la = la.replace("fit_intercept", "fi") la = la.replace("True", "1") la = la.replace("False", "0") la = la.replace("max_depth", "mxd") return la plot_bench_results(df, row_cols=['N', 'onnx_options'], col_cols='method', x_value='dim', hue_cols='fit_intercept', title="%s\nBenchmark scikit-learn / onnxruntime" % model_name, label_fct=label_fct) plt.savefig("%s.png" % filename) import sys if "--quiet" not in sys.argv: plt.show()
############################## # Run the benchmark # +++++++++++++++++ df = run_bench(verbose=True) df.to_csv("plot_bench_polynomial_features_partial_fit.perf.csv", index=False) print(df.head()) ######################### # Extract information about the machine used # ++++++++++++++++++++++++++++++++++++++++++ pkgs = ['numpy', 'pandas', 'sklearn'] dfi = pandas.DataFrame(machine_information(pkgs)) dfi.to_csv("plot_bench_polynomial_features_partial_fit.time.csv", index=False) print(dfi) ############################# # Plot the results # ++++++++++++++++ print(df.columns) plot_bench_results(df, row_cols='N', col_cols=None, x_value='dim', hue_cols=None, cmp_col_values='test', title="PolynomialFeatures + partial_fit\n" "Benchmark scikit-learn PR13290") plt.show()
############################# # Plot the results # ++++++++++++++++ def label_fct(la): la = la.replace("onxpython_compiled", "opy") la = la.replace("onxpython", "opy") la = la.replace("onxonnxruntime1", "ort") la = la.replace("fit_intercept", "fi") la = la.replace("True", "1") la = la.replace("False", "0") la = la.replace("max_depth", "mxd") return la plot_bench_results(df, row_cols=['n_neighbors', 'metric', 'onnx_options'], col_cols=['leaf_size', 'method'], x_value='N', hue_cols=['dim'], title="%s\nBenchmark scikit-learn / onnxruntime" % model_name, label_fct=label_fct) plt.savefig("%s.png" % filename) import sys if "--quiet" not in sys.argv: plt.show()
dfi.to_csv("%s.time.csv" % filename, index=False) print(dfi) ############################# # Plot the results by number of nodes # +++++++++++++++++++++++++++++++++++ def label_fct(la): la = la.replace("onxpython_compiled", "opy") la = la.replace("onxpython", "opy") la = la.replace("onxonnxruntime1", "ort") la = la.replace("edims=(", "edims=(N, ") return la from pymlbenchmark.plotting import plot_bench_results plot_bench_results(df, row_cols='edims', col_cols='axes', x_value='N', cmp_col_values=('lib', 'npy'), title="Benchmark ReduceSum", label_fct=label_fct) plt.savefig("%s.node.png" % filename) import sys if "--quiet" not in sys.argv: plt.show()
# Plot the results # ++++++++++++++++ def label_fct(la): la = la.replace("onxpython_compiled", "opy") la = la.replace("onxpython", "opy") la = la.replace("onxonnxruntime1", "ort") la = la.replace("fit_intercept", "fi") la = la.replace("True", "1") la = la.replace("False", "0") la = la.replace("max_depth", "mxd") return la plot_bench_results(df, row_cols=['N', 'hidden_layer_sizes'], col_cols='method', hue_cols='activation', cmp_col_values=('lib', 'skl'), x_value='dim', y_value='mean', title="%s\nBenchmark scikit-learn / onnxruntime" % model_name, label_fct=label_fct) plt.savefig("%s.png" % filename) import sys if "--quiet" not in sys.argv: plt.show()
'onnxruntime', 'onnx', 'mlprodict'] dfi = pandas.DataFrame(machine_information(pkgs)) dfi.to_csv("%s.time.csv" % filename, index=False) print(dfi) ############################# # Plot the results # ++++++++++++++++ def label_fct(la): la = la.replace("onxpython_compiled", "opy") la = la.replace("onxpython", "opy") la = la.replace("onxonnxruntime1", "ort") la = la.replace("fit_intercept", "fi") la = la.replace("True", "1") la = la.replace("False", "0") la = la.replace("max_depth", "mxd") return la plot_bench_results(df, row_cols='N', col_cols='max_depth', x_value='dim', title="%s\nBenchmark scikit-learn / onnxruntime" % model_name, label_fct=label_fct) plt.savefig("%s.png" % filename) import sys if "--quiet" not in sys.argv: plt.show()
# ++++++++++++++++ def label_fct(la): la = la.replace("onxpython_compiled", "opy") la = la.replace("onxpython", "opy") la = la.replace("onxonnxruntime1", "ort") la = la.replace("fit_intercept", "fi") la = la.replace("True", "1") la = la.replace("False", "0") return la def color_fct(la, col): if "onxpython_compiled" in la: return "red" if "onxpython" in la: return "red" return col plot_bench_results( df, row_cols=['N', 'fit_intercept'], col_cols='method', x_value='dim', title="LogisticRegression\nBenchmark scikit-learn / onnxruntime", label_fct=label_fct, color_fct=color_fct) plt.show()