You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

datasets.py 3.3 kB

6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # -*- coding: utf-8 -*-
  2. # ---
  3. # jupyter:
  4. # jupytext_format_version: '1.2'
  5. # kernelspec:
  6. # display_name: Python 3
  7. # language: python
  8. # name: python3
  9. # language_info:
  10. # codemirror_mode:
  11. # name: ipython
  12. # version: 3
  13. # file_extension: .py
  14. # mimetype: text/x-python
  15. # name: python
  16. # nbconvert_exporter: python
  17. # pygments_lexer: ipython3
  18. # version: 3.5.2
  19. # ---
  20. # ## Datasets
  21. # ## Moons
  22. #
  23. # +
  24. % matplotlib inline
  25. import numpy as np
  26. from sklearn import datasets
  27. import matplotlib.pyplot as plt
  28. # generate sample data
  29. np.random.seed(0)
  30. X, y = datasets.make_moons(200, noise=0.20)
  31. # plot data
  32. plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Spectral)
  33. plt.show()
  34. # -
  35. # ## XOR
  36. # +
  37. import numpy as np
  38. import matplotlib.pyplot as plt
  39. from sklearn.gaussian_process import GaussianProcessClassifier
  40. rng = np.random.RandomState(0)
  41. X = rng.randn(200, 2)
  42. Y = np.logical_xor(X[:, 0] > 0, X[:, 1] > 0)
  43. # plot data
  44. plt.scatter(X[:, 0], X[:, 1], c=Y, cmap=plt.cm.Spectral)
  45. plt.show()
  46. # -
  47. # ## Digital
  48. # +
  49. import matplotlib.pyplot as plt
  50. from sklearn.datasets import load_digits
  51. # load data
  52. digits = load_digits()
  53. # copied from notebook 02_sklearn_data.ipynb
  54. fig = plt.figure(figsize=(6, 6)) # figure size in inches
  55. fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)
  56. # plot the digits: each image is 8x8 pixels
  57. for i in range(64):
  58. ax = fig.add_subplot(8, 8, i + 1, xticks=[], yticks=[])
  59. ax.imshow(digits.images[i], cmap=plt.cm.binary)
  60. # label the image with the target value
  61. ax.text(0, 7, str(digits.target[i]))
  62. # -
  63. # ## Iris
  64. #
  65. # This data sets consists of 3 different types of irises’ (Setosa, Versicolour, and Virginica) petal and sepal length, stored in a 150x4 numpy.ndarray
  66. #
  67. # The rows being the samples and the columns being: Sepal Length, Sepal Width, Petal Length and Petal Width.
  68. #
  69. # +
  70. import matplotlib.pyplot as plt
  71. from mpl_toolkits.mplot3d import Axes3D
  72. from sklearn import datasets
  73. from sklearn.decomposition import PCA
  74. # import some data to play with
  75. iris = datasets.load_iris()
  76. X = iris.data[:, :]
  77. y = iris.target
  78. # Plot the samples
  79. plt.figure(figsize=(15, 5))
  80. plt.subplots_adjust(bottom=.05, top=.9, left=.05, right=.95)
  81. plt.subplot(121)
  82. plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Set1,
  83. edgecolor='k')
  84. plt.xlabel('Sepal length')
  85. plt.ylabel('Sepal width')
  86. plt.subplot(122)
  87. plt.scatter(X[:, 2], X[:, 3], c=y, cmap=plt.cm.Set1,
  88. edgecolor='k')
  89. plt.xlabel('Petal Length')
  90. plt.ylabel('Petal Width')
  91. plt.show()
  92. # +
  93. from sklearn.manifold import Isomap
  94. iso = Isomap(n_neighbors=5, n_components=2)
  95. proj = iso.fit_transform(X)
  96. plt.figure(figsize=(15, 9))
  97. plt.scatter(proj[:, 0], proj[:, 1], c=y)
  98. plt.colorbar()
  99. plt.show()
  100. # -
  101. # ## blobs
  102. #
  103. # +
  104. import matplotlib.pyplot as plt
  105. from sklearn.datasets import make_blobs
  106. # Generate 3 blobs with 2 classes where the second blob contains
  107. # half positive samples and half negative samples. Probability in this
  108. # blob is therefore 0.5.
  109. centers = [(-5, -5), (0, 0), (5, 5)]
  110. n_samples = 500
  111. X, y = make_blobs(n_samples=n_samples, n_features=2, cluster_std=1.0,
  112. centers=centers, shuffle=False, random_state=42)
  113. plt.figure(figsize=(15, 9))
  114. plt.scatter(X[:, 0], X[:, 1], c=y)
  115. plt.colorbar()
  116. plt.show()

机器学习越来越多应用到飞行器、机器人等领域,其目的是利用计算机实现类似人类的智能,从而实现装备的智能化与无人化。本课程旨在引导学生掌握机器学习的基本知识、典型方法与技术,通过具体的应用案例激发学生对该学科的兴趣,鼓励学生能够从人工智能的角度来分析、解决飞行器、机器人所面临的问题和挑战。本课程主要内容包括Python编程基础,机器学习模型,无监督学习、监督学习、深度学习基础知识与实现,并学习如何利用机器学习解决实际问题,从而全面提升自我的《综合能力》。