Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions sklbench/benchmarks/sklearn_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ def get_subset_metrics_of_estimator(
and isinstance(iterations[0], Union[Numeric, NumpyNumeric].__args__)
):
metrics.update({"iterations": int(iterations[0])})
if hasattr(estimator_instance, "estimators_"):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also be set in other types of estimators - for example:
https://scikit-learn.org/stable/modules/generated/sklearn.multiclass.OneVsRestClassifier.html

Perhaps it could check if the first entry there is of tree type.

Also what about cuML? I guess it could be done by calling as_sklearn():
https://docs.rapids.ai/api/cuml/nightly/pickling_cuml_models/#Converting-Between-cuML-and-scikit-learn-Models

estimators_with_trees = [
t
for t in estimator_instance.estimators_
if hasattr(t, "tree_") and hasattr(t.tree_, "node_count")
]
if estimators_with_trees:
metrics["n_nodes"] = sum(
t.tree_.node_count for t in estimators_with_trees
)
if task == "classification":
y_pred = convert_to_numpy(estimator_instance.predict(x))
metrics.update(
Expand Down
2 changes: 2 additions & 0 deletions sklbench/report/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
# NB: 'n_clusters' is parameter of KMeans while
# 'clusters' is number of computer clusters by DBSCAN
"clusters",
# tree ensembles
"n_nodes",
],
"incomparable": [
"1st-mean run ratio",
Expand Down
Loading