Path: blob/master/Data Science using Python/Day 1 Stats Basics.ipynb
3074 views
Kernel: Python 3 (ipykernel)
Statistics is the study of the collection, analysis, interpretation, presentation, and organization of data. In other words, it is a mathematical discipline to collect, summarize data
In [ ]:
In [ ]:
Median
It is the middle value of the data set. It splits the data into two halves.
The median() function is used to calculate the median, i.e middle element of data. If the passed argument is empty, StatisticsError is raised.
In [ ]:
Mode
It is the value that has the highest frequency in the given data set. The data set may have no mode if the frequency of all data points is the same. Also, we can have more than one mode if we encounter two or more data points having the same frequency.
The mode() function returns the number with the maximum number of occurrences. If the passed argument is empty, StatisticsError is raised.
In [ ]:
Measure of Variability
Till now, we have studied the measure of central tendency but this alone is not sufficient to describe the data. To overcome this we need the measure of variability. The measure of variability is known as the spread of data or how well our data is distributed. The most common variability measures are:
Range
The difference between the largest and smallest data point in our data set is known as the range. The range is directly proportional to the spread of data which means the bigger the range, the more the spread of data and vice versa.
Range = Largest data value – smallest data value
We can calculate the maximum and minimum values using the max() and min() methods respectively.
In [ ]:
Variance
It is defined as an average squared deviation from the mean. It is calculated by finding the difference between every data point and the average which is also known as the mean, squaring them, adding all of them, and then dividing by the number of data points present in our data set.
The statistics module provides the variance() method that does all the maths behind the scene. If the passed argument is empty, StatisticsError is raised.
Example: Python code to calculate Variance
In [ ]:
Standard Deviation
It is defined as the square root of the variance. It is calculated by finding the Mean, then subtracting each number from the Mean which is also known as the average, and squaring the result. Adding all the values and then dividing by the no of terms followed by the square root.
The stdev() method of the statistics module returns the standard deviation of the data. If the passed argument is empty, StatisticsError is raised.
Example: Python code to calculate Standard Deviation
In [ ]:
Python – Normal Distribution in Statistics
A probability distribution determines the probability of all the outcomes a random variable takes. The distribution can either be continuous or discrete distribution depending upon the values that a random variable takes. There are several types of probability distribution like Normal distribution, Uniform distribution, exponential distribution, etc. In this article, we will see about Normal distribution and we will also see how we can use Python to plot the Normal distribution.
What is Normal Distribution
The normal distribution is a continuous probability distribution function also known as Gaussian distribution which is symmetric about its mean and has a bell-shaped curve. It is one of the most used probability distributions. Two parameters characterize it
Mean(μ)- It represents the center of the distribution
Standard Deviation(σ) – It represents the spread in the curve
The formula for Normal distribution is
Properties Of Normal Distribution
Symmetric distribution – The normal distribution is symmetric about its mean point. It means the distribution is perfectly balanced toward its mean point with half of the data on either side.
Bell-Shaped curve – The graph of a normal distribution takes the form bell-shaped curve with most of the points accumulated at its mean position. The shape of this curve is determined by the mean and standard deviation of the distribution
Empirical Rule – The normal distribution curve follows the empirical rule where 68% of the data lies within 1 standard deviation from the mean of the graph, 95% of the data lies within 2 standard deviations from the mean and 97% of the data lies within 3 standard deviations from the mean.
Python code for plotting Normal Distribution
In [ ]:
In [ ]: