题目描述:
1.Generate n = 2,000 points uniformly at random in the two-dimensional unit square.Which point do you expect the centroid to be?
2.What objective does the centroid of the points optimize?
3.Apply gradient descent to find the centroid.
4.Apply stochastic gradient descent to find the centroid. Can you say in simple words,what the algorithm is doing?
解析:
1.Generate n = 2,000 points uniformly at random in the two-dimensional unit square. Which point do you expect the centroid to be?
首先生成一个横纵坐标都在0~1范围内的2000个随机散点图。要求的质心就是找到到所有点距离之和最小的点。由于点的生成都是随机的,所以期望的点是 : (0.5,0.5) 。生成散点图代码和图如下:
from scipy import *
import pylab as pl #pylab 模块是一款由python提供的可以绘制二维,三维数据的工具模块,其中包括了绘图软件包 matplotlib
all_points = rand(2000, 2)
pl.plot(all_points[:, 0], all_points[:, 1], 'g.')
pl.show()
2.What objective does the centroid of the points optimize? </