{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Plot randomly generated classification dataset\n\nThis example plots several randomly generated classification datasets.\nFor easy visualization, all datasets have 2 features, plotted on the x and y\naxis. The color of each point represents its class label.\n\nThe first 4 plots use the :func:`~sklearn.datasets.make_classification` with\ndifferent numbers of informative features, clusters per class and classes.\nThe final 2 plots use :func:`~sklearn.datasets.make_blobs` and\n:func:`~sklearn.datasets.make_gaussian_quantiles`.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n\nfrom sklearn.datasets import make_classification\nfrom sklearn.datasets import make_blobs\nfrom sklearn.datasets import make_gaussian_quantiles\n\nplt.figure(figsize=(8, 8))\nplt.subplots_adjust(bottom=0.05, top=0.9, left=0.05, right=0.95)\n\nplt.subplot(321)\nplt.title(\"One informative feature, one cluster per class\", fontsize=\"small\")\nX1, Y1 = make_classification(\n n_features=2, n_redundant=0, n_informative=1, n_clusters_per_class=1\n)\nplt.scatter(X1[:, 0], X1[:, 1], marker=\"o\", c=Y1, s=25, edgecolor=\"k\")\n\nplt.subplot(322)\nplt.title(\"Two informative features, one cluster per class\", fontsize=\"small\")\nX1, Y1 = make_classification(\n n_features=2, n_redundant=0, n_informative=2, n_clusters_per_class=1\n)\nplt.scatter(X1[:, 0], X1[:, 1], marker=\"o\", c=Y1, s=25, edgecolor=\"k\")\n\nplt.subplot(323)\nplt.title(\"Two informative features, two clusters per class\", fontsize=\"small\")\nX2, Y2 = make_classification(n_features=2, n_redundant=0, n_informative=2)\nplt.scatter(X2[:, 0], X2[:, 1], marker=\"o\", c=Y2, s=25, edgecolor=\"k\")\n\nplt.subplot(324)\nplt.title(\"Multi-class, two informative features, one cluster\", fontsize=\"small\")\nX1, Y1 = make_classification(\n n_features=2, n_redundant=0, n_informative=2, n_clusters_per_class=1, n_classes=3\n)\nplt.scatter(X1[:, 0], X1[:, 1], marker=\"o\", c=Y1, s=25, edgecolor=\"k\")\n\nplt.subplot(325)\nplt.title(\"Three blobs\", fontsize=\"small\")\nX1, Y1 = make_blobs(n_features=2, centers=3)\nplt.scatter(X1[:, 0], X1[:, 1], marker=\"o\", c=Y1, s=25, edgecolor=\"k\")\n\nplt.subplot(326)\nplt.title(\"Gaussian divided into three quantiles\", fontsize=\"small\")\nX1, Y1 = make_gaussian_quantiles(n_features=2, n_classes=3)\nplt.scatter(X1[:, 0], X1[:, 1], marker=\"o\", c=Y1, s=25, edgecolor=\"k\")\n\nplt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" } }, "nbformat": 4, "nbformat_minor": 0 }