*Kudos on making it to** **the last and final part of **Mathematics for Machine Learning!** You’ve worked so hard to get to this point and we shall wind this up in the next few minutes!*

*If you haven’t gone through **Part-1**, **Part-2**, **Part-3** **and** **Part 4** **yet** — **Do it right now!*

*Probability and Statistics* are the ** foundational pillars** of

*Machine Learning and Data Science.*In fact, the underlying principle of machine learning and artificial intelligence is nothing but

*statistical mathematics*and

*linear algebra.*

Often you might encounter situations, where you have to read research papers that involve a lot of maths in order to understand a particular topic and so if you want to get better at it, *it’s imperative to have a strong mathematical understanding.*

*Descriptive Statistics**Dispersion**Random Variables**Probability Distributions*

## Getting Started

We shall first see what is Data Analysis, Central Tendency in Python: mean, median, and mode. Moreover, we will discuss Python Dispersion and Python Pandas Descriptive Statistics. Along with this, we will cover the variance in Python and how to calculate the variability for a set of values.

For more on this refer —

Statistical Analysis in Python using Pandas

## Data Analysis

With data analysis, we use two main statistical methods- *Descriptive* and *Inferential*.

- Descriptive statistics uses tools like mean and standard deviation on a sample to summarize data.
- Inferential statistics, on the other hand, looks at data that can randomly vary, and then draw conclusions from it.

Some such variations include observational errors and sampling variation.

## Descriptive Statistics in Python

** Python Descriptive Statistics** process describes the basic features of data in a study. It delivers summaries on the sample and the measures and does not use the data to learn about the population it represents.

Under descriptive statistics, fall two sets of properties-

central tendencyanddispersion. Python Central tendency characterizes one central value for the entire distribution. Measures under this include mean, median, and mode.Python Dispersion is the term for a practice that characterizes how apart the members of the distribution are from the center and from each other. Variance/Standard Deviation is one such measure of variability.

*Implementation:*

We shall begin by importing ** Statistics Library** in Python —

`import statistics as st`

## mean()

This function returns the arithmetic average of the data it operates on.

nums=[1,2,3,5,7,9]

st.mean(nums)Out:4.5

## mode()

This function returns the most common value in a set of data. This gives us a great idea of where the centre lies.

nums=[1,2,3,5,7,9,7,2,7,6]

st.mode(nums)Out:7

## median()

For data of odd length, this returns the middle item; for that of even length, it returns the average of the two middle items.

st.median(nums) #(5+6)/2Out:5.5

## harmonic_mean()

This function returns the harmonic mean of the data. For three values *a, b, and c*, the harmonic mean is- *3/(1/a + 1/b +1/c)*

It is a measure of the centre; one such example would be speed.

st.harmonic_mean([2,4,9.7])Out:3.516616314199396"""for the same set of data, the arithmetic mean would give us a value of 5.233"""

## median_low()

When the data is of an even length, this provides us the low median of the data. Otherwise, it returns the middle value.

st.median_low([1,2,4])Out:2

## median_high()

Like median_low, this returns the high median when the data is of an even length. Otherwise, it returns the middle value.

st.median_high([1,2,4])Out:2

## median_grouped()

This function uses interpolation to return the median of grouped continuous data. This is the 50th percentile.

st.median([1,3,3,5,7])Out:3st.median_grouped([1,3,3,5,7],interval=1)Out:3.25st.median_grouped([1,3,3,5,7],interval=2)Out:3.5

## Python Descriptive Statistics — Dispersion in Python

Dispersion/spread gives us an idea of how the data strays from the typical value.

## variance()

This returns the variance of the sample. This is the ** second moment about the mean** and a larger value denotes a rather spread-out set of data. You can use this when your data is a sample out of a population.

st.variance(nums)Out:7.433333333333334

## pvariance()

This returns the population variance of data. Use this to calculate the variance from an entire population.

st.pvariance(nums)Out:

6.69

## stdev()

This returns the standard deviation for the sample. This is equal to the square root of the sample variance.

st.stdev(nums)Out:

2.7264140062238043

## pstdev()

This returns the population standard deviation. This is the square root of the population variance.

st.pstdev(nums)Out:

2.5865034312755126

## Pandas with Descriptive Statistics in Python

We can do the same things using pandas too (**Statistical Analysis in Python using Pandas**)

import pandas as pd

df=pd.DataFrame(nums)df.mean()

df.mode()

df.std()

df.skew()

## Random Variables

A random variable represents all the possible sets of events an outcome can take. There are two kinds of random variables, ** continuous **and

*discrete.*Events such as coin tosses, dice throws and card games are events that can be represented using

discrete random variables, while values of body heat, atmospheric pressure and student grade point averages(GPA) representscontinuous random variables.

There’s another type of distribution that often pops up in literature which you should know about called ** cumulative distribution function**. All random variables

*(discrete and continuous)*have a

*cumulative distribution function*.

It is a function giving the probability that the random variable *X is less than or equal to x*, for every value x.

For a discrete random variable, the cumulative distribution function is found by

summing up the probabilities.

## Probability Distributions

## 1. Uniform Distribution

Perhaps one of the simplest and useful distribution is the uniform distribution. The probability distribution function of the continuous uniform distribution is —