Skip to content

Commit 1328042

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 6986e9b5db5fa24b268cfc7d8aab32b8962f4510
1 parent 1246612 commit 1328042

File tree

1,015 files changed

+3059
-2977
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,015 files changed

+3059
-2977
lines changed
753 Bytes
Binary file not shown.
711 Bytes
Binary file not shown.

dev/_downloads/plot_bayesian_ridge.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
},
8181
"outputs": [],
8282
"source": [
83-
"lw = 2\nplt.figure(figsize=(6, 5))\nplt.title(\"Weights of the model\")\nplt.plot(clf.coef_, color='lightgreen', linewidth=lw,\n label=\"Bayesian Ridge estimate\")\nplt.plot(w, color='gold', linewidth=lw, label=\"Ground truth\")\nplt.plot(ols.coef_, color='navy', linestyle='--', label=\"OLS estimate\")\nplt.xlabel(\"Features\")\nplt.ylabel(\"Values of the weights\")\nplt.legend(loc=\"best\", prop=dict(size=12))\n\nplt.figure(figsize=(6, 5))\nplt.title(\"Histogram of the weights\")\nplt.hist(clf.coef_, bins=n_features, color='gold', log=True)\nplt.scatter(clf.coef_[relevant_features], 5 * np.ones(len(relevant_features)),\n color='navy', label=\"Relevant features\")\nplt.ylabel(\"Features\")\nplt.xlabel(\"Values of the weights\")\nplt.legend(loc=\"upper left\")\n\nplt.figure(figsize=(6, 5))\nplt.title(\"Marginal log-likelihood\")\nplt.plot(clf.scores_, color='navy', linewidth=lw)\nplt.ylabel(\"Score\")\nplt.xlabel(\"Iterations\")\n\n\n# Plotting some predictions for polynomial regression\ndef f(x, noise_amount):\n y = np.sqrt(x) * np.sin(x)\n noise = np.random.normal(0, 1, len(x))\n return y + noise_amount * noise\n\n\ndegree = 10\nX = np.linspace(0, 10, 100)\ny = f(X, noise_amount=0.1)\nclf_poly = BayesianRidge()\nclf_poly.fit(np.vander(X, degree), y)\n\nX_plot = np.linspace(0, 11, 25)\ny_plot = f(X_plot, noise_amount=0)\ny_mean, y_std = clf_poly.predict(np.vander(X_plot, degree), return_std=True)\nplt.figure(figsize=(6, 5))\nplt.errorbar(X_plot, y_mean, y_std, color='navy',\n label=\"Polynomial Bayesian Ridge Regression\", linewidth=lw)\nplt.plot(X_plot, y_plot, color='gold', linewidth=lw,\n label=\"Ground Truth\")\nplt.ylabel(\"Output y\")\nplt.xlabel(\"Feature X\")\nplt.legend(loc=\"lower left\")\nplt.show()"
83+
"lw = 2\nplt.figure(figsize=(6, 5))\nplt.title(\"Weights of the model\")\nplt.plot(clf.coef_, color='lightgreen', linewidth=lw,\n label=\"Bayesian Ridge estimate\")\nplt.plot(w, color='gold', linewidth=lw, label=\"Ground truth\")\nplt.plot(ols.coef_, color='navy', linestyle='--', label=\"OLS estimate\")\nplt.xlabel(\"Features\")\nplt.ylabel(\"Values of the weights\")\nplt.legend(loc=\"best\", prop=dict(size=12))\n\nplt.figure(figsize=(6, 5))\nplt.title(\"Histogram of the weights\")\nplt.hist(clf.coef_, bins=n_features, color='gold', log=True,\n edgecolor='black')\nplt.scatter(clf.coef_[relevant_features], 5 * np.ones(len(relevant_features)),\n color='navy', label=\"Relevant features\")\nplt.ylabel(\"Features\")\nplt.xlabel(\"Values of the weights\")\nplt.legend(loc=\"upper left\")\n\nplt.figure(figsize=(6, 5))\nplt.title(\"Marginal log-likelihood\")\nplt.plot(clf.scores_, color='navy', linewidth=lw)\nplt.ylabel(\"Score\")\nplt.xlabel(\"Iterations\")\n\n\n# Plotting some predictions for polynomial regression\ndef f(x, noise_amount):\n y = np.sqrt(x) * np.sin(x)\n noise = np.random.normal(0, 1, len(x))\n return y + noise_amount * noise\n\n\ndegree = 10\nX = np.linspace(0, 10, 100)\ny = f(X, noise_amount=0.1)\nclf_poly = BayesianRidge()\nclf_poly.fit(np.vander(X, degree), y)\n\nX_plot = np.linspace(0, 11, 25)\ny_plot = f(X_plot, noise_amount=0)\ny_mean, y_std = clf_poly.predict(np.vander(X_plot, degree), return_std=True)\nplt.figure(figsize=(6, 5))\nplt.errorbar(X_plot, y_mean, y_std, color='navy',\n label=\"Polynomial Bayesian Ridge Regression\", linewidth=lw)\nplt.plot(X_plot, y_plot, color='gold', linewidth=lw,\n label=\"Ground Truth\")\nplt.ylabel(\"Output y\")\nplt.xlabel(\"Feature X\")\nplt.legend(loc=\"lower left\")\nplt.show()"
8484
]
8585
}
8686
],

dev/_downloads/plot_bayesian_ridge.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272

7373
plt.figure(figsize=(6, 5))
7474
plt.title("Histogram of the weights")
75-
plt.hist(clf.coef_, bins=n_features, color='gold', log=True)
75+
plt.hist(clf.coef_, bins=n_features, color='gold', log=True,
76+
edgecolor='black')
7677
plt.scatter(clf.coef_[relevant_features], 5 * np.ones(len(relevant_features)),
7778
color='navy', label="Relevant features")
7879
plt.ylabel("Features")

dev/_downloads/plot_classification.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"print(__doc__)\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.colors import ListedColormap\nfrom sklearn import neighbors, datasets\n\nn_neighbors = 15\n\n# import some data to play with\niris = datasets.load_iris()\nX = iris.data[:, :2] # we only take the first two features. We could\n # avoid this ugly slicing by using a two-dim dataset\ny = iris.target\n\nh = .02 # step size in the mesh\n\n# Create color maps\ncmap_light = ListedColormap(['#FFAAAA', '#AAFFAA', '#AAAAFF'])\ncmap_bold = ListedColormap(['#FF0000', '#00FF00', '#0000FF'])\n\nfor weights in ['uniform', 'distance']:\n # we create an instance of Neighbours Classifier and fit the data.\n clf = neighbors.KNeighborsClassifier(n_neighbors, weights=weights)\n clf.fit(X, y)\n\n # Plot the decision boundary. For that, we will assign a color to each\n # point in the mesh [x_min, x_max]x[y_min, y_max].\n x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1\n y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1\n xx, yy = np.meshgrid(np.arange(x_min, x_max, h),\n np.arange(y_min, y_max, h))\n Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])\n\n # Put the result into a color plot\n Z = Z.reshape(xx.shape)\n plt.figure()\n plt.pcolormesh(xx, yy, Z, cmap=cmap_light)\n\n # Plot also the training points\n plt.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap_bold)\n plt.xlim(xx.min(), xx.max())\n plt.ylim(yy.min(), yy.max())\n plt.title(\"3-Class classification (k = %i, weights = '%s')\"\n % (n_neighbors, weights))\n\nplt.show()"
29+
"print(__doc__)\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.colors import ListedColormap\nfrom sklearn import neighbors, datasets\n\nn_neighbors = 15\n\n# import some data to play with\niris = datasets.load_iris()\n\n# we only take the first two features. We could avoid this ugly\n# slicing by using a two-dim dataset\nX = iris.data[:, :2]\ny = iris.target\n\nh = .02 # step size in the mesh\n\n# Create color maps\ncmap_light = ListedColormap(['#FFAAAA', '#AAFFAA', '#AAAAFF'])\ncmap_bold = ListedColormap(['#FF0000', '#00FF00', '#0000FF'])\n\nfor weights in ['uniform', 'distance']:\n # we create an instance of Neighbours Classifier and fit the data.\n clf = neighbors.KNeighborsClassifier(n_neighbors, weights=weights)\n clf.fit(X, y)\n\n # Plot the decision boundary. For that, we will assign a color to each\n # point in the mesh [x_min, x_max]x[y_min, y_max].\n x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1\n y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1\n xx, yy = np.meshgrid(np.arange(x_min, x_max, h),\n np.arange(y_min, y_max, h))\n Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])\n\n # Put the result into a color plot\n Z = Z.reshape(xx.shape)\n plt.figure()\n plt.pcolormesh(xx, yy, Z, cmap=cmap_light)\n\n # Plot also the training points\n plt.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap_bold,\n edgecolor='k', s=20)\n plt.xlim(xx.min(), xx.max())\n plt.ylim(yy.min(), yy.max())\n plt.title(\"3-Class classification (k = %i, weights = '%s')\"\n % (n_neighbors, weights))\n\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/plot_classification.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717

1818
# import some data to play with
1919
iris = datasets.load_iris()
20-
X = iris.data[:, :2] # we only take the first two features. We could
21-
# avoid this ugly slicing by using a two-dim dataset
20+
21+
# we only take the first two features. We could avoid this ugly
22+
# slicing by using a two-dim dataset
23+
X = iris.data[:, :2]
2224
y = iris.target
2325

2426
h = .02 # step size in the mesh
@@ -46,7 +48,8 @@
4648
plt.pcolormesh(xx, yy, Z, cmap=cmap_light)
4749

4850
# Plot also the training points
49-
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap_bold)
51+
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap_bold,
52+
edgecolor='k', s=20)
5053
plt.xlim(xx.min(), xx.max())
5154
plt.ylim(yy.min(), yy.max())
5255
plt.title("3-Class classification (k = %i, weights = '%s')"

dev/_downloads/plot_concentration_prior.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"# Author: Thierry Guillemot <[email protected]>\n# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\nimport matplotlib.gridspec as gridspec\n\nfrom sklearn.mixture import BayesianGaussianMixture\n\nprint(__doc__)\n\n\ndef plot_ellipses(ax, weights, means, covars):\n for n in range(means.shape[0]):\n eig_vals, eig_vecs = np.linalg.eigh(covars[n])\n unit_eig_vec = eig_vecs[0] / np.linalg.norm(eig_vecs[0])\n angle = np.arctan2(unit_eig_vec[1], unit_eig_vec[0])\n # Ellipse needs degrees\n angle = 180 * angle / np.pi\n # eigenvector normalization\n eig_vals = 2 * np.sqrt(2) * np.sqrt(eig_vals)\n ell = mpl.patches.Ellipse(means[n], eig_vals[0], eig_vals[1],\n 180 + angle)\n ell.set_clip_box(ax.bbox)\n ell.set_alpha(weights[n])\n ell.set_facecolor('#56B4E9')\n ax.add_artist(ell)\n\n\ndef plot_results(ax1, ax2, estimator, X, y, title, plot_title=False):\n ax1.set_title(title)\n ax1.scatter(X[:, 0], X[:, 1], s=5, marker='o', color=colors[y], alpha=0.8)\n ax1.set_xlim(-2., 2.)\n ax1.set_ylim(-3., 3.)\n ax1.set_xticks(())\n ax1.set_yticks(())\n plot_ellipses(ax1, estimator.weights_, estimator.means_,\n estimator.covariances_)\n\n ax2.get_xaxis().set_tick_params(direction='out')\n ax2.yaxis.grid(True, alpha=0.7)\n for k, w in enumerate(estimator.weights_):\n ax2.bar(k, w, width=0.9, color='#56B4E9', zorder=3,\n align='center')\n ax2.text(k, w + 0.007, \"%.1f%%\" % (w * 100.),\n horizontalalignment='center')\n ax2.set_xlim(-.6, 2 * n_components - .4)\n ax2.set_ylim(0., 1.1)\n ax2.tick_params(axis='y', which='both', left='off',\n right='off', labelleft='off')\n ax2.tick_params(axis='x', which='both', top='off')\n\n if plot_title:\n ax1.set_ylabel('Estimated Mixtures')\n ax2.set_ylabel('Weight of each component')\n\n# Parameters of the dataset\nrandom_state, n_components, n_features = 2, 3, 2\ncolors = np.array(['#0072B2', '#F0E442', '#D55E00'])\n\ncovars = np.array([[[.7, .0], [.0, .1]],\n [[.5, .0], [.0, .1]],\n [[.5, .0], [.0, .1]]])\nsamples = np.array([200, 500, 200])\nmeans = np.array([[.0, -.70],\n [.0, .0],\n [.0, .70]])\n\n# mean_precision_prior= 0.8 to minimize the influence of the prior\nestimators = [\n (\"Finite mixture with a Dirichlet distribution\\nprior and \"\n r\"$\\gamma_0=$\", BayesianGaussianMixture(\n weight_concentration_prior_type=\"dirichlet_distribution\",\n n_components=2 * n_components, reg_covar=0, init_params='random',\n max_iter=1500, mean_precision_prior=.8,\n random_state=random_state), [0.001, 1, 1000]),\n (\"Infinite mixture with a Dirichlet process\\n prior and\" r\"$\\gamma_0=$\",\n BayesianGaussianMixture(\n weight_concentration_prior_type=\"dirichlet_process\",\n n_components=2 * n_components, reg_covar=0, init_params='random',\n max_iter=1500, mean_precision_prior=.8,\n random_state=random_state), [1, 1000, 100000])]\n\n# Generate data\nrng = np.random.RandomState(random_state)\nX = np.vstack([\n rng.multivariate_normal(means[j], covars[j], samples[j])\n for j in range(n_components)])\ny = np.concatenate([j * np.ones(samples[j], dtype=int)\n for j in range(n_components)])\n\n# Plot results in two different figures\nfor (title, estimator, concentrations_prior) in estimators:\n plt.figure(figsize=(4.7 * 3, 8))\n plt.subplots_adjust(bottom=.04, top=0.90, hspace=.05, wspace=.05,\n left=.03, right=.99)\n\n gs = gridspec.GridSpec(3, len(concentrations_prior))\n for k, concentration in enumerate(concentrations_prior):\n estimator.weight_concentration_prior = concentration\n estimator.fit(X)\n plot_results(plt.subplot(gs[0:2, k]), plt.subplot(gs[2, k]), estimator,\n X, y, r\"%s$%.1e$\" % (title, concentration),\n plot_title=k == 0)\n\nplt.show()"
29+
"# Author: Thierry Guillemot <[email protected]>\n# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\nimport matplotlib.gridspec as gridspec\n\nfrom sklearn.mixture import BayesianGaussianMixture\n\nprint(__doc__)\n\n\ndef plot_ellipses(ax, weights, means, covars):\n for n in range(means.shape[0]):\n eig_vals, eig_vecs = np.linalg.eigh(covars[n])\n unit_eig_vec = eig_vecs[0] / np.linalg.norm(eig_vecs[0])\n angle = np.arctan2(unit_eig_vec[1], unit_eig_vec[0])\n # Ellipse needs degrees\n angle = 180 * angle / np.pi\n # eigenvector normalization\n eig_vals = 2 * np.sqrt(2) * np.sqrt(eig_vals)\n ell = mpl.patches.Ellipse(means[n], eig_vals[0], eig_vals[1],\n 180 + angle, edgecolor='black')\n ell.set_clip_box(ax.bbox)\n ell.set_alpha(weights[n])\n ell.set_facecolor('#56B4E9')\n ax.add_artist(ell)\n\n\ndef plot_results(ax1, ax2, estimator, X, y, title, plot_title=False):\n ax1.set_title(title)\n ax1.scatter(X[:, 0], X[:, 1], s=5, marker='o', color=colors[y], alpha=0.8)\n ax1.set_xlim(-2., 2.)\n ax1.set_ylim(-3., 3.)\n ax1.set_xticks(())\n ax1.set_yticks(())\n plot_ellipses(ax1, estimator.weights_, estimator.means_,\n estimator.covariances_)\n\n ax2.get_xaxis().set_tick_params(direction='out')\n ax2.yaxis.grid(True, alpha=0.7)\n for k, w in enumerate(estimator.weights_):\n ax2.bar(k, w, width=0.9, color='#56B4E9', zorder=3,\n align='center', edgecolor='black')\n ax2.text(k, w + 0.007, \"%.1f%%\" % (w * 100.),\n horizontalalignment='center')\n ax2.set_xlim(-.6, 2 * n_components - .4)\n ax2.set_ylim(0., 1.1)\n ax2.tick_params(axis='y', which='both', left='off',\n right='off', labelleft='off')\n ax2.tick_params(axis='x', which='both', top='off')\n\n if plot_title:\n ax1.set_ylabel('Estimated Mixtures')\n ax2.set_ylabel('Weight of each component')\n\n# Parameters of the dataset\nrandom_state, n_components, n_features = 2, 3, 2\ncolors = np.array(['#0072B2', '#F0E442', '#D55E00'])\n\ncovars = np.array([[[.7, .0], [.0, .1]],\n [[.5, .0], [.0, .1]],\n [[.5, .0], [.0, .1]]])\nsamples = np.array([200, 500, 200])\nmeans = np.array([[.0, -.70],\n [.0, .0],\n [.0, .70]])\n\n# mean_precision_prior= 0.8 to minimize the influence of the prior\nestimators = [\n (\"Finite mixture with a Dirichlet distribution\\nprior and \"\n r\"$\\gamma_0=$\", BayesianGaussianMixture(\n weight_concentration_prior_type=\"dirichlet_distribution\",\n n_components=2 * n_components, reg_covar=0, init_params='random',\n max_iter=1500, mean_precision_prior=.8,\n random_state=random_state), [0.001, 1, 1000]),\n (\"Infinite mixture with a Dirichlet process\\n prior and\" r\"$\\gamma_0=$\",\n BayesianGaussianMixture(\n weight_concentration_prior_type=\"dirichlet_process\",\n n_components=2 * n_components, reg_covar=0, init_params='random',\n max_iter=1500, mean_precision_prior=.8,\n random_state=random_state), [1, 1000, 100000])]\n\n# Generate data\nrng = np.random.RandomState(random_state)\nX = np.vstack([\n rng.multivariate_normal(means[j], covars[j], samples[j])\n for j in range(n_components)])\ny = np.concatenate([j * np.ones(samples[j], dtype=int)\n for j in range(n_components)])\n\n# Plot results in two different figures\nfor (title, estimator, concentrations_prior) in estimators:\n plt.figure(figsize=(4.7 * 3, 8))\n plt.subplots_adjust(bottom=.04, top=0.90, hspace=.05, wspace=.05,\n left=.03, right=.99)\n\n gs = gridspec.GridSpec(3, len(concentrations_prior))\n for k, concentration in enumerate(concentrations_prior):\n estimator.weight_concentration_prior = concentration\n estimator.fit(X)\n plot_results(plt.subplot(gs[0:2, k]), plt.subplot(gs[2, k]), estimator,\n X, y, r\"%s$%.1e$\" % (title, concentration),\n plot_title=k == 0)\n\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/plot_concentration_prior.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def plot_ellipses(ax, weights, means, covars):
5050
# eigenvector normalization
5151
eig_vals = 2 * np.sqrt(2) * np.sqrt(eig_vals)
5252
ell = mpl.patches.Ellipse(means[n], eig_vals[0], eig_vals[1],
53-
180 + angle)
53+
180 + angle, edgecolor='black')
5454
ell.set_clip_box(ax.bbox)
5555
ell.set_alpha(weights[n])
5656
ell.set_facecolor('#56B4E9')
@@ -71,7 +71,7 @@ def plot_results(ax1, ax2, estimator, X, y, title, plot_title=False):
7171
ax2.yaxis.grid(True, alpha=0.7)
7272
for k, w in enumerate(estimator.weights_):
7373
ax2.bar(k, w, width=0.9, color='#56B4E9', zorder=3,
74-
align='center')
74+
align='center', edgecolor='black')
7575
ax2.text(k, w + 0.007, "%.1f%%" % (w * 100.),
7676
horizontalalignment='center')
7777
ax2.set_xlim(-.6, 2 * n_components - .4)

0 commit comments

Comments
 (0)