源码下载

在本章主要内容:

  • NumPy基础知识
  • 加载iris数据集
  • 查看iris数据集
  • 用pandas查看iris数据集
  • 用NumPy和matplotlib绘图
  • 最小机器学习配方 - SVM分类
  • 介绍交叉验证
  • 以上汇总
  • 机器学习概述 - 分类与回归

简介

本章我们将学习如何使用scikit-learn进行预测。 机器学习强调衡量预测能力,并用scikit-learn进行准确和快速的预测。我们将检查iris数据集,该数据集由三种iris的测量结果组成:Iris Setosa,Iris Versicolor和Iris Virginica。

为了衡量预测,我们将:

  • 保存一些数据以进行测试
  • 仅使用训练数据构建模型
  • 测量测试集的预测能力

解决问题的方法

  • 类别(Classification):
  • 非文本,比如Iris
  • 回归
  • 聚类
  • 降维
  • 技术支持 (可以加qq群:887934385)

NumPy基础

数据科学经常处理结构化的数据表。scikit-learn库需要二维NumPy数组。 在本节中,您将学习

  • NumPy的shape和dimension
  1. In [1]: import numpy as np
  2.  
  3. In [2]: np.arange(10)
  4. Out[2]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
  5.  
  6. In [3]: array_1 = np.arange(10)
  7.  
  8. In [4]: array_1.shape
  9. Out[4]: (10,)
  10.  
  11. In [5]: array_1.ndim
  12. Out[5]: 1
  13.  
  14. In [6]: array_1.reshape((5,2))
  15. Out[6]:
  16. array([[0, 1],
  17. [2, 3],
  18. [4, 5],
  19. [6, 7],
  20. [8, 9]])
  21.  
  22. In [7]: array_1 = array_1.reshape((5,2))
  23.  
  24. In [8]: array_1.ndim
  25. Out[8]: 2
  • NumPy广播(broadcasting)
  1. In [9]: array_1 + 1
  2. Out[9]:
  3. array([[ 1, 2],
  4. [ 3, 4],
  5. [ 5, 6],
  6. [ 7, 8],
  7. [ 9, 10]])
  8.  
  9. In [10]: array_2 = np.arange(10)
  10.  
  11. In [11]: array_2 * array_2
  12. Out[11]: array([ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81])
  13.  
  14. In [12]: array_2 = array_2 ** 2 #Note that this is equivalent to array_2 *
  15.  
  16. In [13]: array_2
  17. Out[13]: array([ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81])
  18.  
  19. In [14]: array_2 = array_2.reshape((5,2))
  20.  
  21. In [15]: array_2
  22. Out[15]:
  23. array([[ 0, 1],
  24. [ 4, 9],
  25. [16, 25],
  26. [36, 49],
  27. [64, 81]])
  28.  
  29. In [16]: array_1 = array_1 + 1
  30.  
  31. In [17]: array_1
  32. Out[17]:
  33. array([[ 1, 2],
  34. [ 3, 4],
  35. [ 5, 6],
  36. [ 7, 8],
  37. [ 9, 10]])
  38.  
  39. In [18]: array_1 + array_2
  40. Out[18]:
  41. array([[ 1, 3],
  42. [ 7, 13],
  43. [21, 31],
  44. [43, 57],
  45. [73, 91]])

  • 初始化NumPy数组和dtypes
  1. In [19]: np.zeros((5,2))
  2. Out[19]:
  3. array([[0., 0.],
  4. [0., 0.],
  5. [0., 0.],
  6. [0., 0.],
  7. [0., 0.]])
  8.  
  9. In [20]: np.ones((5,2), dtype = np.int)
  10. Out[20]:
  11. array([[1, 1],
  12. [1, 1],
  13. [1, 1],
  14. [1, 1],
  15. [1, 1]])
  16.  
  17. In [21]: np.empty((5,2), dtype = np.float)
  18. Out[21]:
  19. array([[0.00000000e+000, 0.00000000e+000],
  20.  
  21. [6.90082649e-310, 6.90082647e-310],
  22. [6.90072710e-310, 6.90072711e-310],
  23. [6.90083466e-310, 0.00000000e+000],
  24. [6.90083921e-310, 1.90979621e-310]])
  • 索引
  1. In [22]: array_1[0,0] #Finds value in first row and first column.
  2. Out[22]: 1
  3.  
  4. In [23]: array_1[0,:] # View the first row
  5. Out[23]: array([1, 2])
  6.  
  7. In [24]: array_1[:,0] # view the first column
  8. Out[24]: array([1, 3, 5, 7, 9])
  9.  
  10. In [25]: array_1[2:5, :]
  11. Out[25]:
  12. array([[ 5, 6],
  13. [ 7, 8],
  14. [ 9, 10]])
  15.  
  16. In [26]: array_1
  17. Out[26]:
  18. array([[ 1, 2],
  19. [ 3, 4],
  20. [ 5, 6],
  21. [ 7, 8],
  22. [ 9, 10]])
  23.  
  24. In [27]: array_1[2:5,0]
  25. Out[27]: array([5, 7, 9])
  • 布尔数组
  1. In [28]: array_1 > 5
  2. Out[28]:
  3. array([[False, False],
  4. [False, False],
  5. [False, True],
  6. [ True, True],
  7. [ True, True]])
  8.  
  9. In [29]: array_1[array_1 > 5]
  10. Out[29]: array([ 6, 7, 8, 9, 10])
  • 算术运算
  1. In [30]: array_1.sum()
  2. Out[30]: 55
  3.  
  4. In [31]: array_1.sum(axis = 1) # Find all the sums by row:
  5. Out[31]: array([ 3, 7, 11, 15, 19])
  6.  
  7. In [32]: array_1.sum(axis = 0) # Find all the sums by column
  8. Out[32]: array([25, 30])
  9.  
  10. In [33]: array_1.mean(axis = 0)
  11. Out[33]: array([5., 6.])
  • NaN值
  1. # Scikit-learn不接受np.nan
  2. In [34]: array_3 = np.array([np.nan, 0, 1, 2, np.nan])
  3.  
  4. In [35]: np.isnan(array_3)
  5. Out[35]: array([ True, False, False, False, True])
  6.  
  7. In [36]: array_3[~np.isnan(array_3)]
  8. Out[36]: array([0., 1., 2.])
  9.  
  10. In [37]: array_3[np.isnan(array_3)] = 0
  11.  
  12. In [38]: array_3
  13. Out[38]: array([0., 0., 1., 2., 0.])

Scikit-learn只接受实数的二维NumPy数组,没有缺失的np.nan值。从经验来看,最好将np.nan改为某个值丢弃。 就我个人而言,我喜欢跟踪布尔模板并保持数据的形状大致相同,因为这会导致更少的编码错误和更多的编码灵活性。

加载数据

  1. In [1]: import numpy as np
  2.  
  3. In [2]: import pandas as pd
  4.  
  5. In [3]: import matplotlib.pyplot as plt
  6.  
  7. In [4]: from sklearn import datasets
  8.  
  9. In [5]: iris = datasets.load_iris()
  10.  
  11. In [6]: iris.data
  12. Out[6]:
  13. array([[5.1, 3.5, 1.4, 0.2],
  14. [4.9, 3. , 1.4, 0.2],
  15. [4.7, 3.2, 1.3, 0.2],
  16. [4.6, 3.1, 1.5, 0.2],
  17. [5. , 3.6, 1.4, 0.2],
  18. [5.4, 3.9, 1.7, 0.4],
  19. [4.6, 3.4, 1.4, 0.3],
  20. [5. , 3.4, 1.5, 0.2],
  21. [4.4, 2.9, 1.4, 0.2],
  22. [4.9, 3.1, 1.5, 0.1],
  23. [5.4, 3.7, 1.5, 0.2],
  24. [4.8, 3.4, 1.6, 0.2],
  25. [4.8, 3. , 1.4, 0.1],
  26. [4.3, 3. , 1.1, 0.1],
  27. [5.8, 4. , 1.2, 0.2],
  28. [5.7, 4.4, 1.5, 0.4],
  29. [5.4, 3.9, 1.3, 0.4],
  30. [5.1, 3.5, 1.4, 0.3],
  31. [5.7, 3.8, 1.7, 0.3],
  32. [5.1, 3.8, 1.5, 0.3],
  33. [5.4, 3.4, 1.7, 0.2],
  34. [5.1, 3.7, 1.5, 0.4],
  35. [4.6, 3.6, 1. , 0.2],
  36. [5.1, 3.3, 1.7, 0.5],
  37. [4.8, 3.4, 1.9, 0.2],
  38. [5. , 3. , 1.6, 0.2],
  39. [5. , 3.4, 1.6, 0.4],
  40. [5.2, 3.5, 1.5, 0.2],
  41. [5.2, 3.4, 1.4, 0.2],
  42. [4.7, 3.2, 1.6, 0.2],
  43. [4.8, 3.1, 1.6, 0.2],
  44. [5.4, 3.4, 1.5, 0.4],
  45. [5.2, 4.1, 1.5, 0.1],
  46. [5.5, 4.2, 1.4, 0.2],
  47. [4.9, 3.1, 1.5, 0.1],
  48. [5. , 3.2, 1.2, 0.2],
  49. [5.5, 3.5, 1.3, 0.2],
  50. [4.9, 3.1, 1.5, 0.1],
  51. [4.4, 3. , 1.3, 0.2],
  52. [5.1, 3.4, 1.5, 0.2],
  53. [5. , 3.5, 1.3, 0.3],
  54. [4.5, 2.3, 1.3, 0.3],
  55. [4.4, 3.2, 1.3, 0.2],
  56. [5. , 3.5, 1.6, 0.6],
  57. [5.1, 3.8, 1.9, 0.4],
  58. [4.8, 3. , 1.4, 0.3],
  59. [5.1, 3.8, 1.6, 0.2],
  60. [4.6, 3.2, 1.4, 0.2],
  61. [5.3, 3.7, 1.5, 0.2],
  62. [5. , 3.3, 1.4, 0.2],
  63. [7. , 3.2, 4.7, 1.4],
  64. [6.4, 3.2, 4.5, 1.5],
  65. [6.9, 3.1, 4.9, 1.5],
  66. [5.5, 2.3, 4. , 1.3],
  67. [6.5, 2.8, 4.6, 1.5],
  68. [5.7, 2.8, 4.5, 1.3],
  69. [6.3, 3.3, 4.7, 1.6],
  70. [4.9, 2.4, 3.3, 1. ],
  71. [6.6, 2.9, 4.6, 1.3],
  72. [5.2, 2.7, 3.9, 1.4],
  73. [5. , 2. , 3.5, 1. ],
  74. [5.9, 3. , 4.2, 1.5],
  75. [6. , 2.2, 4. , 1. ],
  76. [6.1, 2.9, 4.7, 1.4],
  77. [5.6, 2.9, 3.6, 1.3],
  78. [6.7, 3.1, 4.4, 1.4],
  79. [5.6, 3. , 4.5, 1.5],
  80. [5.8, 2.7, 4.1, 1. ],
  81. [6.2, 2.2, 4.5, 1.5],
  82. [5.6, 2.5, 3.9, 1.1],
  83. [5.9, 3.2, 4.8, 1.8],
  84. [6.1, 2.8, 4. , 1.3],
  85. [6.3, 2.5, 4.9, 1.5],
  86. [6.1, 2.8, 4.7, 1.2],
  87. [6.4, 2.9, 4.3, 1.3],
  88. [6.6, 3. , 4.4, 1.4],
  89. [6.8, 2.8, 4.8, 1.4],
  90. [6.7, 3. , 5. , 1.7],
  91. [6. , 2.9, 4.5, 1.5],
  92. [5.7, 2.6, 3.5, 1. ],
  93. [5.5, 2.4, 3.8, 1.1],
  94. [5.5, 2.4, 3.7, 1. ],
  95. [5.8, 2.7, 3.9, 1.2],
  96. [6. , 2.7, 5.1, 1.6],
  97. [5.4, 3. , 4.5, 1.5],
  98. [6. , 3.4, 4.5, 1.6],
  99. [6.7, 3.1, 4.7, 1.5],
  100. [6.3, 2.3, 4.4, 1.3],
  101. [5.6, 3. , 4.1, 1.3],
  102. [5.5, 2.5, 4. , 1.3],
  103. [5.5, 2.6, 4.4, 1.2],
  104. [6.1, 3. , 4.6, 1.4],
  105. [5.8, 2.6, 4. , 1.2],
  106. [5. , 2.3, 3.3, 1. ],
  107. [5.6, 2.7, 4.2, 1.3],
  108. [5.7, 3. , 4.2, 1.2],
  109. [5.7, 2.9, 4.2, 1.3],
  110. [6.2, 2.9, 4.3, 1.3],
  111. [5.1, 2.5, 3. , 1.1],
  112. [5.7, 2.8, 4.1, 1.3],
  113. [6.3, 3.3, 6. , 2.5],
  114. [5.8, 2.7, 5.1, 1.9],
  115. [7.1, 3. , 5.9, 2.1],
  116. [6.3, 2.9, 5.6, 1.8],
  117. [6.5, 3. , 5.8, 2.2],
  118. [7.6, 3. , 6.6, 2.1],
  119. [4.9, 2.5, 4.5, 1.7],
  120. [7.3, 2.9, 6.3, 1.8],
  121. [6.7, 2.5, 5.8, 1.8],
  122. [7.2, 3.6, 6.1, 2.5],
  123. [6.5, 3.2, 5.1, 2. ],
  124. [6.4, 2.7, 5.3, 1.9],
  125. [6.8, 3. , 5.5, 2.1],
  126. [5.7, 2.5, 5. , 2. ],
  127. [5.8, 2.8, 5.1, 2.4],
  128. [6.4, 3.2, 5.3, 2.3],
  129. [6.5, 3. , 5.5, 1.8],
  130. [7.7, 3.8, 6.7, 2.2],
  131. [7.7, 2.6, 6.9, 2.3],
  132. [6. , 2.2, 5. , 1.5],
  133. [6.9, 3.2, 5.7, 2.3],
  134. [5.6, 2.8, 4.9, 2. ],
  135. [7.7, 2.8, 6.7, 2. ],
  136. [6.3, 2.7, 4.9, 1.8],
  137. [6.7, 3.3, 5.7, 2.1],
  138. [7.2, 3.2, 6. , 1.8],
  139. [6.2, 2.8, 4.8, 1.8],
  140. [6.1, 3. , 4.9, 1.8],
  141. [6.4, 2.8, 5.6, 2.1],
  142. [7.2, 3. , 5.8, 1.6],
  143. [7.4, 2.8, 6.1, 1.9],
  144. [7.9, 3.8, 6.4, 2. ],
  145. [6.4, 2.8, 5.6, 2.2],
  146. [6.3, 2.8, 5.1, 1.5],
  147. [6.1, 2.6, 5.6, 1.4],
  148. [7.7, 3. , 6.1, 2.3],
  149. [6.3, 3.4, 5.6, 2.4],
  150. [6.4, 3.1, 5.5, 1.8],
  151. [6. , 3. , 4.8, 1.8],
  152. [6.9, 3.1, 5.4, 2.1],
  153. [6.7, 3.1, 5.6, 2.4],
  154. [6.9, 3.1, 5.1, 2.3],
  155. [5.8, 2.7, 5.1, 1.9],
  156. [6.8, 3.2, 5.9, 2.3],
  157. [6.7, 3.3, 5.7, 2.5],
  158. [6.7, 3. , 5.2, 2.3],
  159. [6.3, 2.5, 5. , 1.9],
  160. [6.5, 3. , 5.2, 2. ],
  161. [6.2, 3.4, 5.4, 2.3],
  162. [5.9, 3. , 5.1, 1.8]])
  163.  
  164. In [7]: iris.data.shape
  165. Out[7]: (150, 4)
  166.  
  167. In [8]: iris.data[0]
  168. Out[8]: array([5.1, 3.5, 1.4, 0.2])
  169.  
  170. In [9]: iris.feature_names
  171. Out[9]:
  172. ['sepal length (cm)',
  173. 'sepal width (cm)',
  174. 'petal length (cm)',
  175. 'petal width (cm)']
  176.  
  177. In [10]: iris.target
  178. Out[10]:
  179. array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  181. 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  182. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  183. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  184. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  185. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])
  186.  
  187. In [11]: iris.target.shape
  188. Out[11]: (150,)
  189.  
  190. In [12]: iris.target_names
  191. Out[12]: array(['setosa', 'versicolor', 'virginica'], dtype='<U10')
  • 用pandas查看数据
  1. import numpy as np #Load the numpy library for fast array computations
  2. import pandas as pd #Load the pandas data-analysis library
  3. import matplotlib.pyplot as plt #Load the pyplot visualization library
  4.  
  5. %matplotlib inline
  6.  
  7. from sklearn import datasets
  8. iris = datasets.load_iris()
  9.  
  10. iris_df = pd.DataFrame(iris.data, columns = iris.feature_names)
  11.  
  12. iris_df['sepal length (cm)'].hist(bins=30)

```

!python

for class_number in np.unique(iris.target): plt.figure(1) iris_df['sepal length (cm)'].iloc[np.where(iris.target == class_number)[0]].hist(bins=30)

  1. ![Alt Text]({filename}/images/scikit-learn-cookbook1-pandas2.png)
  2.  
  3. ```
  4. #!python
  5.  
  6. np.where(iris.target == class_number)[0]

执行结果

  1. array([100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
  2. 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
  3. 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138,
  4. 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149], dtype=int64)

matplotlib和NumPy作图

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. %matplotlib inline
  4.  
  5. plt.plot(np.arange(10), np.arange(10))
  6.  
  7. plt.plot(np.arange(10), np.exp(np.arange(10)))
  8.  
  9. # 两张图片放在一起
  10. plt.figure()
  11. plt.subplot(121)
  12. plt.plot(np.arange(10), np.exp(np.arange(10)))
  13. plt.subplot(122)
  14. plt.scatter(np.arange(10), np.exp(np.arange(10)))
  15.  
  16. plt.figure()
  17. plt.subplot(211)
  18. plt.plot(np.arange(10), np.exp(np.arange(10)))
  19. plt.subplot(212)
  20. plt.scatter(np.arange(10), np.exp(np.arange(10)))
  21.  
  22. plt.figure()
  23. plt.subplot(221)
  24. plt.plot(np.arange(10), np.exp(np.arange(10)))
  25. plt.subplot(222)
  26. plt.scatter(np.arange(10), np.exp(np.arange(10)))
  27. plt.subplot(223)
  28. plt.scatter(np.arange(10), np.exp(np.arange(10)))
  29. plt.subplot(224)
  30. plt.scatter(np.arange(10), np.exp(np.arange(10)))
  31.  
  32. from sklearn.datasets import load_iris
  33.  
  34. iris = load_iris()
  35. data = iris.data
  36. target = iris.target
  37.  
  38. # Resize the figure for better viewing
  39. plt.figure(figsize=(12,5))
  40.  
  41. # First subplot
  42. plt.subplot(121)
  43.  
  44. # Visualize the first two columns of data:
  45. plt.scatter(data[:,0], data[:,1], c=target)
  46.  
  47. # Second subplot
  48. plt.subplot(122)
  49.  
  50. # Visualize the last two columns of data:
  51. plt.scatter(data[:,2], data[:,3], c=target)
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. %matplotlib inline
  4.  
  5. plt.plot(np.arange(10), np.arange(10))
  6.  
  7. plt.plot(np.arange(10), np.exp(np.arange(10)))
  8.  
  9. # 两张图片放在一起
  10. plt.figure()
  11. plt.subplot(121)
  12. plt.plot(np.arange(10), np.exp(np.arange(10)))
  13. plt.subplot(122)
  14. plt.scatter(np.arange(10), np.exp(np.arange(10)))
  15.  
  16. plt.figure()
  17. plt.subplot(211)
  18. plt.plot(np.arange(10), np.exp(np.arange(10)))
  19. plt.subplot(212)
  20. plt.scatter(np.arange(10), np.exp(np.arange(10)))
  21.  
  22. plt.figure()
  23. plt.subplot(221)
  24. plt.plot(np.arange(10), np.exp(np.arange(10)))
  25. plt.subplot(222)
  26. plt.scatter(np.arange(10), np.exp(np.arange(10)))
  27. plt.subplot(223)
  28. plt.scatter(np.arange(10), np.exp(np.arange(10)))
  29. plt.subplot(224)
  30. plt.scatter(np.arange(10), np.exp(np.arange(10)))
  31.  
  32. from sklearn.datasets import load_iris
  33.  
  34. iris = load_iris()
  35. data = iris.data
  36. target = iris.target
  37.  
  38. # Resize the figure for better viewing
  39. plt.figure(figsize=(12,5))
  40.  
  41. # First subplot
  42. plt.subplot(121)
  43.  
  44. # Visualize the first two columns of data:
  45. plt.scatter(data[:,0], data[:,1], c=target)
  46.  
  47. # Second subplot
  48. plt.subplot(122)
  49.  
  50. # Visualize the last two columns of data:
  51. plt.scatter(data[:,2], data[:,3], c=target)

执行结果参见

最小机器学习快速入门 - 向量机分类

为了做出预测,我们将: * 说明要解决的问题 * 选择一个模型来解决问题 * 训练模型 * 作出预测 * 衡量模型的表现如何

scikit-learn_cookbook1: 高性能机器学习-NumPy的更多相关文章

  1. [机器学习]numpy broadcast shape 机制

    最近在做机器学习的时候,对未知对webshell检测,发现代码提示:ValueError: operands could not be broadcast together with shapes ( ...

  2. 机器学习- Numpy基础 吐血整理

    Numpy是专门为数据科学或者数据处理相关的需求设计的一个高效的组件.听起来是不是挺绕口的,其实简单来说就2个方面,一是Numpy是专门处理数据的,二是Numpy在处理数据方面很牛逼(肯定比Pytho ...

  3. 机器学习 Numpy库入门

    2017-06-28 13:56:25 Numpy 提供了一个强大的N维数组对象ndarray,提供了线性代数,傅里叶变换和随机数生成等的基本功能,可以说Numpy是Scipy,Pandas等科学计算 ...

  4. 第四十篇 入门机器学习——Numpy.array的基本操作——向量及矩阵的运算

    No.1. Numpy.array相较于Python原生List的性能优势 No.2. 将向量或矩阵中的每个元素 + 1 No.2. 将向量或矩阵中的所有元素 - 1 No.3. 将向量或矩阵中的所有 ...

  5. 第三十七篇 入门机器学习——Numpy基础

    No.1. 查看numpy版本 No.2. 为了方便使用numpy,在导入时顺便起个别名 No.3. numpy.array的基本操作:创建.查询.修改 No.4. 用dtype查看当前元素的数据类型 ...

  6. 第四十三篇 入门机器学习——Numpy的基本操作——Fancy Indexing

    No.1. 通过索引快速访问向量中的多个元素 No.2. 用索引对应的元素快速生成一个矩阵 No.3. 通过索引从矩阵中快速获取多个元素 No.4. 获取矩阵中感兴趣的行或感兴趣的列,重新组成矩阵 N ...

  7. 第四十二篇 入门机器学习——Numpy的基本操作——索引相关

    No.1. 使用np.argmin和np.argmax来获取向量元素中最小值和最大值的索引 No.2. 使用np.random.shuffle将向量中的元素顺序打乱,操作后,原向量发生改变:使用np. ...

  8. 第四十一篇 入门机器学习——Numpy的基本操作——聚合操作

    No.1. 对向量元素求和使用np.sum,也可以使用类似big_array.sum()的方式 No.2. 对向量元素求最小值使用np.min,求最大值使用np.max,也可以使用类似big_arra ...

  9. 第三十九篇 入门机器学习——Numpy.array的基础操作——合并与分割向量和矩阵

    No.1. 初始化状态 No.2. 合并多个向量为一个向量 No.3. 合并多个矩阵为一个矩阵 No.4. 借助vstack和hstack实现矩阵与向量的快速合并.或多个矩阵快速合并 No.5. 分割 ...

随机推荐

  1. 简单的Dos Unity操作(debug)

    使用adb命令启动Unity app,eg: adb shell am start -S -a android.intent.action.MAIN -n co.spe3d.sticker/com.u ...

  2. SpringBoot的Banner

    一 官方文档介绍 1 自定义横幅 通过在 classpath 中添加banner.txt文件或将banner.location设置为此类文件的位置,可以更改启动时打印的横幅.如果文件具有异常编码,则可 ...

  3. 你不知道的Canvas(二)

    你不知道的Canvas(二) 一.色彩Colors 到目前为止,我们只看到过绘制内容的方法.如果我们想要给图形上色,有两个重要的属性可以做到:fillStyle 和 strokeStyle. fill ...

  4. python中的列表list练习

    列表: 1.增 1.1 append,在列表的末尾追加元素,使用方法:list.append('元素') li = ['alex', 'wusir', 'eric', 'rain', 'alex'] ...

  5. Python3爬虫(1)_使用Urllib进行网络爬取

    网络爬虫 又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者,是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本.另外一些不常使用的名字还有蚂蚁.自动索引.模拟程序或者蠕虫 ...

  6. 还不会用FindBugs?你的代码质量很可能令人堪忧

    前言 项目中代码质量,往往需要比较有经验的程序员的审查来保证.但是随着项目越来越大,代码审查会变得越来越复杂,需要耗费越来越多的人力.而且程序员的经验和精力都是有限的,能审查出问题必定有限.而在对代码 ...

  7. 蓝牙耳机没声音,用mac平台下的safari时

    买了个蓝牙耳机,发现用其他本地播放器或者chrome的时候有声音, 但是用safari的时候没有声音,最后发现是flash的问题. 只要清除浏览数据后刷新就有声音了

  8. 爬虫之scrapy简介

    原始的爬虫流程:效率低.同步.阻塞 scrapy执行流程:效率高.异步.非阻塞 scrapy的概念 scrapy是一个爬虫框架 开发速度快 稳定性高 性能优越 scrapy的流程 1. 爬虫模块(Sp ...

  9. 网络安全-主动信息收集篇第二章-三层网络发现之ping

    第三层网络扫描基于TCP/IP.ICMP协议. 优点:可路由.速度比较快 缺点:相对于二层网络扫描较慢,容易被边界防火墙过滤 所有扫描发现技术,都会有相应的对抗办法,所以无论是来自二层的网络扫描还是来 ...

  10. 考试T3麻将

    这题就是一个简单的暴力,但考试的时候不知道脑子在想什么,什么都没打出来,也许是我想的太多了... 这道题对于不会打麻将的人来说还是有点难理解规则的,我没说过我会打麻将,这里是题目链接. 20分思路,利 ...