广州双城热恋创意文化传播有限公司

现在的位置: 主页 > 联系方式 > 文章列表

文章正文

学习大数据第五天:最小二乘法的Python实现(二)

作者:广州双城热恋创意文化传播有限公司 来源:www.666loveyou.com 发布时间:2017-09-08 18:18:01
学习大数据第五天:最小二乘法的Python实现(二)

1.numpy.random.normal


numpy.random.normal numpy.random.normal(loc=0.0,scale=1.0,size=None)

Draw random samples from a normal (Gaussian) distribution.

The probability density function of the normal distribution, first derived by De Moivre and 200 years later by both Gauss and Laplace independently[R250], is often called the bell curve because of its characteristic shape (see the example below).

The normal distributions occurs often in nature. For example, it describes the commonly occurring distribution of samples influenced by a large number of tiny, random disturbances, each with its own unique distribution[R250].

Parameters:

loc: float

Mean (“centre”) of the distribution.

scale: float

Standard deviation (spread or “width”) of the distribution.

size: int or tuple of ints, optional

Output shape. If the given shape is, e.g.,(m,n,k), thenm*n*ksamples are drawn. Default is None, in which case a single value is returned.

See also

scipy.stats.distributions.normprobability density function, distribution or cumulative density function, etc.

Notes

The probability density for the Gaussian distribution is

whereis the mean andthe standard deviation. The square of the standard deviation,, is called the variance.

The function has its peak at the mean, and its “spread” increases with the standard deviation (the function reaches 0.607 times its maximum atand[R250]). This implies thatnumpy.random.normalis more likely to return samples lying close to the mean, rather than those far away.

References

[R249] Wikipedia, “Normal distribution”, [R250] (1,2,3,4)P. R. Peebles Jr., “Central Limit Theorem” in “Probability, Random Variables and Random Signal Principles”, 4th ed., 2001, pp. 51, 51, 125.

Examples

Draw samples from the distribution:

>>> >>> mu, sigma = 0, 0.1 # mean and standard deviation >>> s = np.random.normal(mu, sigma, 1000)

Verify the mean and the variance:

>>> >>> abs(mu - np.mean(s)) < 0.01 True >>> >>> abs(sigma - np.std(s, ddof=1)) < 0.01 True

Display the histogram of the samples, along with the probability density function:

>>> >>> import matplotlib.pyplot as plt >>> count, bins, ignored = plt.hist(s, 30, normed=True) >>> plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) * ... np.exp( - (bins - mu)**2 / (2 * sigma**2) ), ... linewidth=2, color='r') >>> plt.show()

(Source code,png,pdf)

../../_images/numpy-random-normal-1.png

2.numpy.random.randn


import numpy as np
np.random.randn(2,3)


array([[ 0.59941534, 1.0991949 , 1.36316028], [-0.01979197, 1.30783162, -0.69808199]])

意思是从标准正太分布中随机抽取。


3.scipy.optimize.leastsq

最小二乘法


企业建站2800元起,携手武汉肥猫科技,做一个有见地的颜值派!更多优惠请戳:恩施网站建设 http://enshi.45qun.com


COPYRIGHT © 2015 广州双城热恋创意文化传播有限公司 ALL RIGHTS RESERVED.
网站地图 技术支持:肥猫科技
精彩专题:网站建设
购买本站友情链接、项目合作请联系客服QQ:2500-38-100