Python Statistics Module
We will be looking at light weight module called Statistics module which has the common methods of analysis in it. We will look at
1. Mean
2. Median
3. Quantiles
4. Variance
5. Correlation
6. Standard Deviation
7. Covariance
8. Normal Distribution Plot
We will import the random module to get the data for our analysis and usage
import random, statistics
import seaborn as snsLook at the methods of the module using the dir() method on the statistics module.
dir(statistics)We will create some random data for our purposes using the random module.
x=[random.random() for x in range(10)]
y=[random.random() for x in range(10)]x,y
sns.distplot(x)
This is the plot that we see from the random data that we created.
sns.distplot(y)
Calculating the mean for our set of data.
statistics.mean(x),statistics.mean(y)
Calculating the median for our set of data.
statistics.median(x),statistics.median(y)
Calculating the quantiles for our set of data. It will give the 0.25,0.5,0.75 quantiles.
statistics.quantiles(x),statistics.quantiles(y)
Calculating the variances for our set of data.
statistics.variance(x),statistics.variance(y)
Calculating the standard deviation for our set of data.
statistics.stdev(x),statistics.stdev(y)
Calculating the correlation for our set of data.
statistics.correlation(x,y)
Calculating the covariance for our set of data.
statistics.covariance(x,y)
Creating a normal distribution from the mean and standard deviation of our data.
data=statistics.NormalDist(statistics.mean(x),statistics.stdev(x))Plot the distribution in seaborn.
sns.distplot(data.samples(n=100))
Comments
Post a Comment