Mafunzo ya Machine Learning - Scatter Plot

Scatter Plot

Scatter plots are graphs where each value in the dataset is represented by a point.


Matplotlib module has a method for drawing scatter plots, which requires two arrays of the same length, one for the x-axis values and the other for the y-axis values:

x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]

The x array represents the age of each car.

The y array represents the speed of each car.

实例

Please use scatter() Method for drawing scatter plots:

import matplotlib.pyplot as plt
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]
plt.scatter(x, y)
plt.show()

结果:


运行实例

散点图解释

Ukubwa wa x na y kinaingia na umeme wa mafanikio.

Inasikia kwenye picha, mafanikio mawili yasiyotumika kwa miaka 2, mafanikio yasiyotumika kwa miaka 12.

注释:汽车似乎越新,驾驶速度就越快,但这可能是一个巧合,毕竟我们只注册了 13 辆汽车。

随机数据分布

在机器学习中,数据集可以包含成千上万甚至数百万个值。

测试算法时,您可能没有真实的数据,您可能必须使用随机生成的值。

正如我们在上一章中学到的那样,NumPy 模块可以帮助我们!

让我们创建两个数组,它们都填充有来自正态数据分布的 1000 个随机数。

第一个数组的平均值设置为 5.0,标准差为 1.0。

第二个数组的平均值设置为 10.0,标准差为 2.0:

实例

有 1000 个点的散点图:

import numpy
import matplotlib.pyplot as plt
x = numpy.random.normal(5.0, 1.0, 1000)
y = numpy.random.normal(10.0, 2.0, 1000)
plt.scatter(x, y)
plt.show()

结果:


运行实例

散点图解释

我们可以看到,点集中在 x 轴上的值 5 和 y 轴上的 10 周围。

我们还可以看到,在 y 轴上扩散得比在 x 轴上更大。