|
7 | 7 | Features 1 and 2 of the diabetes-dataset are fitted and
|
8 | 8 | plotted below. It illustrates that although feature 2
|
9 | 9 | has a strong coefficient on the full model, it does not
|
10 |
| -give us much regarding `y` when compared to just feature 1 |
11 |
| -
|
| 10 | +give us much regarding `y` when compared to just feature 1. |
12 | 11 | """
|
13 | 12 |
|
14 | 13 | # Code source: Gaël Varoquaux
|
15 | 14 | # Modified for documentation by Jaques Grobler
|
16 | 15 | # License: BSD 3 clause
|
17 | 16 |
|
18 |
| -import matplotlib.pyplot as plt |
19 |
| -import numpy as np |
20 |
| -from mpl_toolkits.mplot3d import Axes3D |
| 17 | +# %% |
| 18 | +# First we load the diabetes dataset. |
21 | 19 |
|
22 |
| -from sklearn import datasets, linear_model |
| 20 | +from sklearn import datasets |
| 21 | +import numpy as np |
23 | 22 |
|
24 | 23 | X, y = datasets.load_diabetes(return_X_y=True)
|
25 | 24 | indices = (0, 1)
|
|
29 | 28 | y_train = y[:-20]
|
30 | 29 | y_test = y[-20:]
|
31 | 30 |
|
| 31 | +# %% |
| 32 | +# Next we fit a linear regression model. |
| 33 | + |
| 34 | +from sklearn import linear_model |
| 35 | + |
32 | 36 | ols = linear_model.LinearRegression()
|
33 |
| -ols.fit(X_train, y_train) |
| 37 | +_ = ols.fit(X_train, y_train) |
| 38 | + |
| 39 | + |
| 40 | +# %% |
| 41 | +# Finally we plot the figure from three different views. |
| 42 | + |
| 43 | +import matplotlib.pyplot as plt |
34 | 44 |
|
35 | 45 |
|
36 |
| -# ############################################################################# |
37 |
| -# Plot the figure |
38 | 46 | def plot_figs(fig_num, elev, azim, X_train, clf):
|
39 | 47 | fig = plt.figure(fig_num, figsize=(4, 3))
|
40 | 48 | plt.clf()
|
41 |
| - ax = Axes3D(fig, elev=elev, azim=azim) |
| 49 | + ax = fig.add_subplot(111, projection="3d", elev=elev, azim=azim) |
42 | 50 |
|
43 | 51 | ax.scatter(X_train[:, 0], X_train[:, 1], y_train, c="k", marker="+")
|
44 | 52 | ax.plot_surface(
|
|
0 commit comments