Skip to content

Commit 57437b5

Browse files
authored
DOC use polars in plot_digits_pipe example (#28576)
1 parent 15ecc0e commit 57437b5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

examples/compose/plot_digits_pipe.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import matplotlib.pyplot as plt
1818
import numpy as np
19-
import pandas as pd
19+
import polars as pl
2020

2121
from sklearn import datasets
2222
from sklearn.decomposition import PCA
@@ -63,11 +63,15 @@
6363
ax0.legend(prop=dict(size=12))
6464

6565
# For each number of components, find the best classifier results
66-
results = pd.DataFrame(search.cv_results_)
6766
components_col = "param_pca__n_components"
68-
best_clfs = results.groupby(components_col)[
69-
[components_col, "mean_test_score", "std_test_score"]
70-
].apply(lambda g: g.nlargest(1, "mean_test_score"))
67+
is_max_test_score = pl.col("mean_test_score") == pl.col("mean_test_score").max()
68+
best_clfs = (
69+
pl.LazyFrame(search.cv_results_)
70+
.filter(is_max_test_score.over(components_col))
71+
.unique(components_col)
72+
.sort(components_col)
73+
.collect()
74+
)
7175
ax1.errorbar(
7276
best_clfs[components_col],
7377
best_clfs["mean_test_score"],

0 commit comments

Comments
 (0)