Skip to content

Commit

Permalink
DOC use polars in plot_digits_pipe example (scikit-learn#28576)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli authored Mar 7, 2024
1 parent 15ecc0e commit 57437b5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions examples/compose/plot_digits_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import polars as pl

from sklearn import datasets
from sklearn.decomposition import PCA
Expand Down Expand Up @@ -63,11 +63,15 @@
ax0.legend(prop=dict(size=12))

# For each number of components, find the best classifier results
results = pd.DataFrame(search.cv_results_)
components_col = "param_pca__n_components"
best_clfs = results.groupby(components_col)[
[components_col, "mean_test_score", "std_test_score"]
].apply(lambda g: g.nlargest(1, "mean_test_score"))
is_max_test_score = pl.col("mean_test_score") == pl.col("mean_test_score").max()
best_clfs = (
pl.LazyFrame(search.cv_results_)
.filter(is_max_test_score.over(components_col))
.unique(components_col)
.sort(components_col)
.collect()
)
ax1.errorbar(
best_clfs[components_col],
best_clfs["mean_test_score"],
Expand Down

0 comments on commit 57437b5

Please sign in to comment.