From 2c3e1fde7614057ac3deb637993134e7a9661c3d Mon Sep 17 00:00:00 2001 From: Shuowei Li Date: Mon, 23 Dec 2024 22:55:47 +0000 Subject: [PATCH] docs: add linear model example (#1235) * docs: add linear model example * chore: add experimental series.blob.display() function (#1232) * add an extra setting to set display prgress bar to None * docs: add KMeans example (#1234) * docs: add KMeans example * fix test * skip non deterministic examples * docs: add examples for ml PCA and SimpleImputer (#1236) * docs: add examples for ml PCA and SimpleImputer * fix * fix * fix doctest bug * add extra lines to fix docs bug * fix docstring bug * remove an extra line --------- Co-authored-by: Shuowei Li Co-authored-by: Garrett Wu <6505921+GarrettWu@users.noreply.github.com> --- .../sklearn/linear_model/_base.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/third_party/bigframes_vendored/sklearn/linear_model/_base.py b/third_party/bigframes_vendored/sklearn/linear_model/_base.py index d6b8a473bd..21ba5a3bf8 100644 --- a/third_party/bigframes_vendored/sklearn/linear_model/_base.py +++ b/third_party/bigframes_vendored/sklearn/linear_model/_base.py @@ -62,6 +62,30 @@ class LinearRegression(RegressorMixin, LinearModel): to minimize the residual sum of squares between the observed targets in the dataset, and the targets predicted by the linear approximation. + **Examples:** + + >>> from bigframes.ml.linear_model import LinearRegression + >>> import bigframes.pandas as bpd + >>> bpd.options.display.progress_bar = None + >>> X = bpd.DataFrame({ \ + "feature0": [20, 21, 19, 18], \ + "feature1": [0, 1, 1, 0], \ + "feature2": [0.2, 0.3, 0.4, 0.5]}) + >>> y = bpd.DataFrame({"outcome": [0, 0, 1, 1]}) + >>> # Create the linear model + >>> model = LinearRegression() + >>> model.fit(X, y) + LinearRegression() + + >>> # Score the model + >>> score = model.score(X, y) + >>> print(score) # doctest:+SKIP + mean_absolute_error mean_squared_error mean_squared_log_error \ + 0 0.022812 0.000602 0.00035 + median_absolute_error r2_score explained_variance + 0 0.015077 0.997591 0.997591 + + Args: optimize_strategy (str, default "auto_strategy"): The strategy to train linear regression models. Possible values are