From 475948e0d7b9049be3903b309cd3378f639635a4 Mon Sep 17 00:00:00 2001 From: Sam Adam-Day Date: Fri, 18 Feb 2022 18:13:39 +0000 Subject: [PATCH 1/5] Updated sklearn.utils.get_chunk_n_rows docstring to conform with numpydoc --- sklearn/tests/test_docstrings.py | 1 - sklearn/utils/__init__.py | 11 ++++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sklearn/tests/test_docstrings.py b/sklearn/tests/test_docstrings.py index 52279ad878512..bad56495b868b 100644 --- a/sklearn/tests/test_docstrings.py +++ b/sklearn/tests/test_docstrings.py @@ -142,7 +142,6 @@ "sklearn.utils.fixes.threadpool_limits", "sklearn.utils.gen_batches", "sklearn.utils.gen_even_slices", - "sklearn.utils.get_chunk_n_rows", "sklearn.utils.graph.graph_shortest_path", "sklearn.utils.graph.single_source_shortest_path_length", "sklearn.utils.is_scalar_nan", diff --git a/sklearn/utils/__init__.py b/sklearn/utils/__init__.py index cfe68609357d7..637d7c1c6053b 100644 --- a/sklearn/utils/__init__.py +++ b/sklearn/utils/__init__.py @@ -941,7 +941,7 @@ def _print_elapsed_time(source, message=None): def get_chunk_n_rows(row_bytes, *, max_n_rows=None, working_memory=None): - """Calculates how many rows can be processed within working_memory. + """Calculate how many rows can be processed within `working_memory`. Parameters ---------- @@ -951,17 +951,18 @@ def get_chunk_n_rows(row_bytes, *, max_n_rows=None, working_memory=None): max_n_rows : int, default=None The maximum return value. working_memory : int or float, default=None - The number of rows to fit inside this number of MiB will be returned. - When None (default), the value of + The number of rows to fit inside this number of MiB will be + returned. When None (default), the value of ``sklearn.get_config()['working_memory']`` is used. Returns ------- - int or the value of n_samples + int + The number of rows which can be processed within `working_memory`. Warns ----- - Issues a UserWarning if ``row_bytes`` exceeds ``working_memory`` MiB. + Issues a UserWarning if `row_bytes exceeds `working_memory` MiB. """ if working_memory is None: From 9bfa3bba9aada0399b7716d6f3883f8f661466ad Mon Sep 17 00:00:00 2001 From: Sam Adam-Day Date: Sat, 19 Feb 2022 15:37:05 +0000 Subject: [PATCH 2/5] Use notebook-style for plot_ols_3d --- examples/linear_model/plot_ols_3d.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/examples/linear_model/plot_ols_3d.py b/examples/linear_model/plot_ols_3d.py index 2c9e0c7a91bc0..adc7fe16b2edc 100644 --- a/examples/linear_model/plot_ols_3d.py +++ b/examples/linear_model/plot_ols_3d.py @@ -7,14 +7,16 @@ Features 1 and 2 of the diabetes-dataset are fitted and plotted below. It illustrates that although feature 2 has a strong coefficient on the full model, it does not -give us much regarding `y` when compared to just feature 1 - +give us much regarding `y` when compared to just feature 1. """ # Code source: Gaƫl Varoquaux # Modified for documentation by Jaques Grobler # License: BSD 3 clause +# %% +# First we load the diabetes dataset. + import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.mplot3d import Axes3D @@ -29,12 +31,15 @@ y_train = y[:-20] y_test = y[-20:] +# %% +# Next we fit a linear regression model. + ols = linear_model.LinearRegression() ols.fit(X_train, y_train) -# ############################################################################# -# Plot the figure +# %% +# Finally we plot the figure from three different views. def plot_figs(fig_num, elev, azim, X_train, clf): fig = plt.figure(fig_num, figsize=(4, 3)) plt.clf() From a1516aff10bf9a1149e231810f9c676dc87950f8 Mon Sep 17 00:00:00 2001 From: Sam Adam-Day Date: Tue, 22 Feb 2022 18:34:03 +0000 Subject: [PATCH 3/5] Small tweaks to plot_ols_3d example --- examples/linear_model/plot_ols_3d.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/linear_model/plot_ols_3d.py b/examples/linear_model/plot_ols_3d.py index adc7fe16b2edc..ccfccf603b9f4 100644 --- a/examples/linear_model/plot_ols_3d.py +++ b/examples/linear_model/plot_ols_3d.py @@ -17,11 +17,8 @@ # %% # First we load the diabetes dataset. -import matplotlib.pyplot as plt +from sklearn import datasets import numpy as np -from mpl_toolkits.mplot3d import Axes3D - -from sklearn import datasets, linear_model X, y = datasets.load_diabetes(return_X_y=True) indices = (0, 1) @@ -34,16 +31,24 @@ # %% # Next we fit a linear regression model. +from sklearn import linear_model + ols = linear_model.LinearRegression() -ols.fit(X_train, y_train) +_ = ols.fit(X_train, y_train) # %% # Finally we plot the figure from three different views. + +import matplotlib.pyplot as plt +from mpl_toolkits.mplot3d import Axes3D + + def plot_figs(fig_num, elev, azim, X_train, clf): fig = plt.figure(fig_num, figsize=(4, 3)) plt.clf() - ax = Axes3D(fig, elev=elev, azim=azim) + ax = Axes3D(fig, elev=elev, azim=azim, auto_add_to_figure=False) + fig.add_axes(ax) ax.scatter(X_train[:, 0], X_train[:, 1], y_train, c="k", marker="+") ax.plot_surface( From 492c53c91ae85f8cd4a8667534ad4f50539745f7 Mon Sep 17 00:00:00 2001 From: Sam Adam-Day Date: Tue, 22 Feb 2022 18:59:53 +0000 Subject: [PATCH 4/5] No longer use add_axes() in plot_ols_3d --- examples/linear_model/plot_ols_3d.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/linear_model/plot_ols_3d.py b/examples/linear_model/plot_ols_3d.py index ccfccf603b9f4..6f7e9ecf1445a 100644 --- a/examples/linear_model/plot_ols_3d.py +++ b/examples/linear_model/plot_ols_3d.py @@ -47,8 +47,7 @@ def plot_figs(fig_num, elev, azim, X_train, clf): fig = plt.figure(fig_num, figsize=(4, 3)) plt.clf() - ax = Axes3D(fig, elev=elev, azim=azim, auto_add_to_figure=False) - fig.add_axes(ax) + ax = Axes3D(fig, elev=elev, azim=azim) ax.scatter(X_train[:, 0], X_train[:, 1], y_train, c="k", marker="+") ax.plot_surface( From ca03b14e27476c51960209cf3bb94ce4ae6f5305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Wed, 23 Feb 2022 07:56:09 +0100 Subject: [PATCH 5/5] Fix warnings in matplotlib 3.5 --- examples/linear_model/plot_ols_3d.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/linear_model/plot_ols_3d.py b/examples/linear_model/plot_ols_3d.py index 6f7e9ecf1445a..222226c6b28c2 100644 --- a/examples/linear_model/plot_ols_3d.py +++ b/examples/linear_model/plot_ols_3d.py @@ -41,13 +41,12 @@ # Finally we plot the figure from three different views. import matplotlib.pyplot as plt -from mpl_toolkits.mplot3d import Axes3D def plot_figs(fig_num, elev, azim, X_train, clf): fig = plt.figure(fig_num, figsize=(4, 3)) plt.clf() - ax = Axes3D(fig, elev=elev, azim=azim) + ax = fig.add_subplot(111, projection="3d", elev=elev, azim=azim) ax.scatter(X_train[:, 0], X_train[:, 1], y_train, c="k", marker="+") ax.plot_surface(