|
- # ---
- # jupyter:
- # jupytext_format_version: '1.2'
- # 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.5.2
- # ---
-
- # ## Datasets
-
- # ## Moons
- #
-
- # +
- % matplotlib inline
- import numpy as np
- from sklearn import datasets
- import matplotlib.pyplot as plt
-
- # generate sample data
- np.random.seed(0)
- X, y = datasets.make_moons(200, noise=0.20)
-
- # plot data
- plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Spectral)
- plt.show()
- # -
-
- # ## XOR
-
- # +
- import numpy as np
- import matplotlib.pyplot as plt
-
- from sklearn.gaussian_process import GaussianProcessClassifier
-
- rng = np.random.RandomState(0)
- X = rng.randn(200, 2)
- Y = np.logical_xor(X[:, 0] > 0, X[:, 1] > 0)
-
- # plot data
- plt.scatter(X[:, 0], X[:, 1], c=Y, cmap=plt.cm.Spectral)
- plt.show()
- # -
-
- # ## Digital
-
- # +
- import matplotlib.pyplot as plt
- from sklearn.datasets import load_digits
-
- # load data
- digits = load_digits()
-
- # copied from notebook 02_sklearn_data.ipynb
- fig = plt.figure(figsize=(6, 6)) # figure size in inches
- fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)
-
- # plot the digits: each image is 8x8 pixels
- for i in range(64):
- ax = fig.add_subplot(8, 8, i + 1, xticks=[], yticks=[])
- ax.imshow(digits.images[i], cmap=plt.cm.binary)
-
- # label the image with the target value
- ax.text(0, 7, str(digits.target[i]))
|