2011-12-16 06:04:03 +08:00
|
|
|
"""
|
|
|
|
|
==============================================
|
|
|
|
|
Plot randomly generated classification dataset
|
|
|
|
|
==============================================
|
|
|
|
|
|
2020-05-09 07:15:10 +08:00
|
|
|
This example plots several randomly generated classification datasets.
|
|
|
|
|
For easy visualization, all datasets have 2 features, plotted on the x and y
|
|
|
|
|
axis. The color of each point represents its class label.
|
|
|
|
|
|
|
|
|
|
The first 4 plots use the :func:`~sklearn.datasets.make_classification` with
|
|
|
|
|
different numbers of informative features, clusters per class and classes.
|
|
|
|
|
The final 2 plots use :func:`~sklearn.datasets.make_blobs` and
|
|
|
|
|
:func:`~sklearn.datasets.make_gaussian_quantiles`.
|
|
|
|
|
"""
|
2011-12-16 06:26:08 +08:00
|
|
|
|
2013-02-01 22:04:03 +08:00
|
|
|
print(__doc__)
|
2011-12-16 06:04:03 +08:00
|
|
|
|
2014-05-15 04:31:03 +08:00
|
|
|
import matplotlib.pyplot as plt
|
2011-12-16 06:04:03 +08:00
|
|
|
|
|
|
|
|
from sklearn.datasets import make_classification
|
2014-03-25 16:16:16 +08:00
|
|
|
from sklearn.datasets import make_blobs
|
|
|
|
|
from sklearn.datasets import make_gaussian_quantiles
|
2011-12-16 06:04:03 +08:00
|
|
|
|
2014-03-25 16:16:16 +08:00
|
|
|
plt.figure(figsize=(8, 8))
|
2014-05-15 04:31:03 +08:00
|
|
|
plt.subplots_adjust(bottom=.05, top=.9, left=.05, right=.95)
|
2011-12-16 06:26:08 +08:00
|
|
|
|
2014-03-25 16:16:16 +08:00
|
|
|
plt.subplot(321)
|
|
|
|
|
plt.title("One informative feature, one cluster per class", fontsize='small')
|
2011-12-16 06:04:03 +08:00
|
|
|
X1, Y1 = make_classification(n_features=2, n_redundant=0, n_informative=1,
|
2012-12-25 20:16:05 +08:00
|
|
|
n_clusters_per_class=1)
|
2017-06-28 20:56:27 +08:00
|
|
|
plt.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1,
|
|
|
|
|
s=25, edgecolor='k')
|
2011-12-16 06:04:03 +08:00
|
|
|
|
2014-03-25 16:16:16 +08:00
|
|
|
plt.subplot(322)
|
|
|
|
|
plt.title("Two informative features, one cluster per class", fontsize='small')
|
2011-12-16 06:04:03 +08:00
|
|
|
X1, Y1 = make_classification(n_features=2, n_redundant=0, n_informative=2,
|
2012-12-25 20:16:05 +08:00
|
|
|
n_clusters_per_class=1)
|
2017-06-28 20:56:27 +08:00
|
|
|
plt.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1,
|
|
|
|
|
s=25, edgecolor='k')
|
2011-12-16 06:04:03 +08:00
|
|
|
|
2014-03-25 16:16:16 +08:00
|
|
|
plt.subplot(323)
|
2017-06-28 20:56:27 +08:00
|
|
|
plt.title("Two informative features, two clusters per class",
|
|
|
|
|
fontsize='small')
|
2011-12-16 06:04:03 +08:00
|
|
|
X2, Y2 = make_classification(n_features=2, n_redundant=0, n_informative=2)
|
2017-06-28 20:56:27 +08:00
|
|
|
plt.scatter(X2[:, 0], X2[:, 1], marker='o', c=Y2,
|
|
|
|
|
s=25, edgecolor='k')
|
2011-12-16 06:04:03 +08:00
|
|
|
|
2014-03-25 16:16:16 +08:00
|
|
|
plt.subplot(324)
|
2014-05-15 04:31:03 +08:00
|
|
|
plt.title("Multi-class, two informative features, one cluster",
|
2014-05-15 10:35:13 +08:00
|
|
|
fontsize='small')
|
2011-12-16 06:04:03 +08:00
|
|
|
X1, Y1 = make_classification(n_features=2, n_redundant=0, n_informative=2,
|
2012-12-25 20:16:05 +08:00
|
|
|
n_clusters_per_class=1, n_classes=3)
|
2017-06-28 20:56:27 +08:00
|
|
|
plt.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1,
|
|
|
|
|
s=25, edgecolor='k')
|
2011-12-16 06:04:03 +08:00
|
|
|
|
2014-03-25 16:16:16 +08:00
|
|
|
plt.subplot(325)
|
|
|
|
|
plt.title("Three blobs", fontsize='small')
|
|
|
|
|
X1, Y1 = make_blobs(n_features=2, centers=3)
|
2017-06-28 20:56:27 +08:00
|
|
|
plt.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1,
|
|
|
|
|
s=25, edgecolor='k')
|
2014-03-25 16:16:16 +08:00
|
|
|
|
|
|
|
|
plt.subplot(326)
|
|
|
|
|
plt.title("Gaussian divided into three quantiles", fontsize='small')
|
|
|
|
|
X1, Y1 = make_gaussian_quantiles(n_features=2, n_classes=3)
|
2017-06-28 20:56:27 +08:00
|
|
|
plt.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1,
|
|
|
|
|
s=25, edgecolor='k')
|
2014-03-25 16:16:16 +08:00
|
|
|
|
2014-05-15 04:31:03 +08:00
|
|
|
plt.show()
|