8000 DOC: use notebook-style for plot_ols_3d by SamAdamDay · Pull Request #22547 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

DOC: use notebook-style for plot_ols_3d #22547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions examples/linear_model/plot_ols_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@
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

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
# %%
# First we load the diabetes dataset.

from sklearn import datasets, linear_model
from sklearn import datasets
import numpy as np

X, y = datasets.load_diabetes(return_X_y=True)
indices = (0, 1)
Expand All @@ -29,16 +28,25 @@
y_train = y[:-20]
y_test = y[-20:]

# %%
# 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


# #############################################################################
# Plot the figure
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(
Expand Down
0