We will generate random values that mimic a normal distribution and analyze the generated data with statistical functions from the scipy.stats
package. Perform the following steps to do so:
scipy.stats
package.generated = stats.norm.rvs(size=900)
print “Mean”, “Std”, stats.norm.fit(generated)
The mean and standard deviation would be shown as follows:
Mean Std (0.0071293257063200707, 0.95537708218972528)
pvalue
instances range from 0 to 1.print “Skewtest”, “pvalue”, stats.skewtest(generated)
The result of the skewness test would be shown as follows:
Skewtest pvalue (-0.62120640688766893, 0.5344638245033837)
So there is a 53 percent chance that we are dealing with a normal distribution.
print “Kurtosistest”, “pvalue”, stats.kurtosistest(generated)
The result of the kurtosis test would be shown as follows:
Kurtosistest pvalue (1.3065381019536981, 0.19136963054975586)
print “Normaltest”, “pvalue”, stats.normaltest(generated)
The result of the normality test would be shown as follows:
Normaltest pvalue (2.09293921181506, 0.35117535059841687)
print “95 percentile”, stats.scoreatpercentile(generated, 95)
The value at the 95th percentile would be shown as follows:
95 percentile 1.54048860252
print “Percentile at 1”, stats.percentileofscore(generated, 1)
The percentile at 1 would be shown as follows:
Percentile at 1 85.5555555556
plt.hist(generated) plt.show()
The following is the histogram of the generated random values:
We created a data set from a normal distribution and analyzed it with the scipy.stats
module (see statistics.py
).
from scipy import stats import matplotlib.pyplot as plt generated = stats.norm.rvs(size=900) print “Mean”, “Std”, stats.norm.fit(generated) print “Skewtest”, “pvalue”, stats.skewtest(generated) print “Kurtosistest”, “pvalue”, stats.kurtosistest(generated) print “Normaltest”, “pvalue”, stats.normaltest(generated) print “95 percentile”, stats.scoreatpercentile(generated, 95) print “Percentile at 1”, stats.percentileofscore(generated, 1) plt.hist(generated) plt.show()