Skip to content

Commit 0d84459

Browse files
authored
docs: add examples for ml PCA and SimpleImputer (#1236)
* docs: add examples for ml PCA and SimpleImputer * fix * fix
1 parent d87ab97 commit 0d84459

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

third_party/bigframes_vendored/sklearn/decomposition/_pca.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,30 @@
2020
class PCA(BaseEstimator, metaclass=ABCMeta):
2121
"""Principal component analysis (PCA).
2222
23+
**Examples:**
24+
25+
>>> import bigframes.pandas as bpd
26+
>>> from bigframes.ml.decomposition import PCA
27+
>>> bpd.options.display.progress_bar = None
28+
>>> X = bpd.DataFrame({"feat0": [-1, -2, -3, 1, 2, 3], "feat1": [-1, -1, -2, 1, 1, 2]})
29+
>>> pca = PCA(n_components=2).fit(X)
30+
>>> pca.predict(X) # doctest:+SKIP
31+
principal_component_1 principal_component_2
32+
0 -0.755243 0.157628
33+
1 -1.05405 -0.141179
34+
2 -1.809292 0.016449
35+
3 0.755243 -0.157628
36+
4 1.05405 0.141179
37+
5 1.809292 -0.016449
38+
<BLANKLINE>
39+
[6 rows x 2 columns]
40+
>>> pca.explained_variance_ratio_ # doctest:+SKIP
41+
principal_component_id explained_variance_ratio
42+
0 1 0.00901
43+
1 0 0.99099
44+
<BLANKLINE>
45+
[2 rows x 2 columns]
46+
2347
Args:
2448
n_components (int, float or None, default None):
2549
Number of components to keep. If n_components is not set, all

third_party/bigframes_vendored/sklearn/impute/_base.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ class SimpleImputer(_BaseImputer):
1818
Replace missing values using a descriptive statistic (e.g. mean, median, or
1919
most frequent) along each column.
2020
21+
**Examples:**
22+
23+
>>> import bigframes.pandas as bpd
24+
>>> from bigframes.ml.impute import SimpleImputer
25+
>>> bpd.options.display.progress_bar = None
26+
>>> X_train = bpd.DataFrame({"feat0": [7.0, 4.0, 10.0], "feat1": [2.0, None, 5.0], "feat2": [3.0, 6.0, 9.0]})
27+
>>> imp_mean = SimpleImputer().fit(X_train)
28+
>>> X_test = bpd.DataFrame({"feat0": [None, 4.0, 10.0], "feat1": [2.0, None, None], "feat2": [3.0, 6.0, 9.0]})
29+
>>> imp_mean.transform(X_test)
30+
imputer_feat0 imputer_feat1 imputer_feat2
31+
0 7.0 2.0 3.0
32+
1 4.0 3.5 6.0
33+
2 10.0 3.5 9.0
34+
<BLANKLINE>
35+
[3 rows x 3 columns]
36+
2137
Args:
2238
strategy ({'mean', 'median', 'most_frequent'}, default='mean'):
2339
The imputation strategy. 'mean': replace missing values using the mean along

0 commit comments

Comments
 (0)