Maths
Maths
What is Statistics?
Statistics is the study of the collection, analysis, interpretation, presentation, and
organization of data. OR Statistics is the science of analysing data.. Father of Statistics is Sir
Ronald Aylmer Fisher.
NOTE:
Good statistical explanations are also useful for predictions
Quantitative Data
Information about something that is described by numbers.
Examples:
Income, Age, Height
Types of Statistics
There are 2 types of statistics:
Descriptive Statistics
Inferential Statistics
Descriptive Statistics
The information (data) from your sample or population can be visualized with graphs or
summarized by numbers. This will show key information in a simpler way than just looking at
raw data. It can help us understand how the data is distributed. Graphs can visually show
the data distribution.
Examples of graphs include:
Histograms
Pie charts
Bar graphs
Box plots
The Mean
x̄=∑ x/n
The Mean Value is the Average of all values.
This table contains 11 values:
To find the Mean Value: Add all values and divide by the number of values.
The Mean Value is:
(7+8+8+9+9+9+10+11+14+14+15)/11 = 10.3636363636.
The Mean is the Sum divided by the Count.
Example Coding:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Machine Learning</h2>
<p>Calculate the mean (average) value.</p>
<div id="demo"></div>
<script>
let mean = (7+8+8+9+9+9+10+11+14+14+15)/11;
document.getElementById("demo").innerHTML = mean;
</script>
</body>
</html>
The Median is the value in the middle (after the values are sorted):
77,78,85,86,86,86,87,87,88,94,99,103,111
Example Coding:
<!DOCTYPE html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/9.3.0/math.js"></script>
<body>
<h1>Machine Learning</h1>
<p>The Median is the mid point value:</p>
<div id="demo"></div>
<script>
const speed = [99,86,87,88,111,86,103,87,94,78,77,85,86];
let median = math.median(speed);
document.getElementById("demo").innerHTML = median;
</script>
</body>
</html>
If there are two numbers in the middle, divide the sum of them by two.
77,78,85,86,86,86,87,87,88,94,99,103
(86 + 87) / 2 = 86.5
The Mode
The Mode Value is the value that appears the most number of times:
99,86,87,88,111,86,103,87,94,78,77,85,86
Example Code:
<!DOCTYPE html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/9.3.0/math.js"></script>
<body>
<h1>Machine Learning</h1>
<p>The Mode is the most common value:</p>
<div id="demo"></div>
<script>
const speed = [99,86,87,88,111,86,103,87,94,78,77,85,86];
let mode = math.mode(speed);
document.getElementById("demo").innerHTML = mode;
</script>
</body>
</html>
Mode = Term with Highest Frequency
For example: {2, 3, 4, 2, 4, 6, 4, 7, 7, 4, 2, 4}
4 is the most frequent term in this data set.
Thus, mode is 4.
1. Range
It is a given measure of how to spread apart values in a sample set or data set.
Range = Maximum value – Minimum value
The Variance
In statistics, the Variance is the average of the squared differences from the Mean
Value.
In other words, the variance describes how far a set of numbers is Spread Out from
the mean (average) value.
Mean value is described already
We will first use the data set with 10 observations to give an example of how we can
calculate the variance:
Example2:
This table contains 11 values:
Example:
<html>
<body>
<h1>Machine Learning</h1>
<p>Calculate the Variance.</p>
<div id="demo"></div>
<script>
// Calulate the Mean (m)
let m = (7+8+8+9+9+9+10+11+14+14+15)/11;
// Calculate the Sum of Sqares (ss)
let ss = (7-m)**2 + (8-m)**2 + (8-m)**2 + (9-m)**2 + (9-m)**2 + (9-m)**2 + (10-
m)**2 + (11-m)**2 + (14-m)**2 + (14-m)**2 + (15-m)**2;
// Calculate the Variance
let variance = ss / 11;
// Diplay the Variance
document.getElementById("demo").innerHTML = variance;
</script>
</body>
</html>
Standard Deviation
Standard Deviation is a measure of how spread out numbers are.
The symbol is σ (Greek letter sigma).
The formula is the √ variance (the square root of the variance).
Deviation is a measure of Distance.
How far (on average), all values are from the Mean (the Middle).
A mathematical function will have difficulties in predicting precise values, if the observations
are "spread". Standard deviation is a measure of uncertainty. A low standard deviation
means that most of the numbers are close to the mean (average) value. A high standard
deviation means that the values are spread out over a wider range.
NOTE: Standard Deviation is often represented by the symbol Sigma: σ
Example:
import pandas as pd
import numpy as np
full_health_data = pd.read_csv("FHealthData.csv", header=0, sep=",")
std = np.std(full_health_data)
print(std)
Example Code:in JS
<!DOCTYPE html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/9.3.0/math.js"></script>
<body>
<h2>JavaScript Machine Learning</h2>
<p>Calculate the Standard Deviation</p>
<div id="demo"></div>
<script>
// Calculate the Standard Deviation
const values = [7,8,8,9,9,9,9,10,11,14,15];
let std = math.std(values, "uncorrected");
document.getElementById("demo").innerHTML = std;
</script>
</body>
</html>
Coefficient of Variation
The coefficient of variation is used to get an idea of how large the standard deviation is.
Outliers
Outliers are values "outside" the other values:
99,86,87,88,111,86,103,87,94,78,300,85,86
Outliers can change the mean a lot. Sometimes we don't use them (they might be an error),
or we use the median or the mode instead.
Example:
<!DOCTYPE html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/9.3.0/math.js"></script>
<body>
<h1>Machine Learning</h1>
<p>Calculate the mean (average) value.</p>
<div id="demo"></div>
<script>
const values = [99,86,87,88,111,86,103,87,94,78,300,85,86];
let mean = math.mean(values);
document.getElementById("demo").innerHTML = mean;
</script>
</body>
</html>
Inferential Statistics
Inferential statistics are methods for quantifying properties of a population from a small
Sample:
You take data from a sample and make a prediction about the whole population.
For example, you can stand in a shop and ask a sample of 100 people if they like chocolate.
From your research, using inferential statistics, you could predict that 91% of all shoppers
like chocolate.
Incredible Chocolate Facts
• Nine out of ten people love chocolate.
• 50% of the US population cannot live without chocolate every day.
• You use Inferential Statistics to predict whole domains from small samples
of data.
Hypothesis Testing
It is a method to check if a claim about a population is true. More precisely, it checks how
likely it is that a hypothesis is true is based on the sample data.
There are different types of hypothesis testing.
A single group
Comparing one group to another
Comparing the same group before and after a change
Types of Numbers:
PROBABILITY
Probability means possibility. It is a branch of mathematics that deals with the occurrence
of a random event. The value is expressed from zero to one. Father of probability is Blaise
Pascal. Probability theory starts with basic concepts such as random experiments, sample
spaces, events, and the probability of events.
Terms in Probability
Probability of an Event
The probability of an event is a measure of the likelihood that the event will occur, expressed
as a number between 0 and 1. An event with a probability of 1 is considered certain to
happen, while an event with a probability of 0 is certain not to happen.
Probability is about how Likely something is to occur, or how likely something is true.
The mathematic probability is a Number between 0 and 1.
0 indicates Impossibility and 1 indicates Certainty.
Different types of events in probability.
Equally Likely Events
Equally likely events are those whose chances or probabilities of happening are equal. Both
events are not related to one another. For example, there are equal possibilities of receiving
either a head or a tail when we flip a coin.
Exhaustive Events
We call an event exhaustive when the set of all experiment results is the same as the sample
space.
Mutually Exclusive Events
Events that are mutually exclusive cannot occur at the same time. For instance, the weather
may be hot or chilly simultaneously. We can’t have the same weather at the same time.
Probability Formula
P(E) = Number of favourable outcomes / Total number of outcomes
Note: where P(E) denotes the probability of an event E.
Probability Tree Diagram
A tree diagram in probability is a graphic representation that helps us in determining the
likely outcomes that is whether an event will occur or not. It helps us understand the all
possibilities of an event and which possibilities can occur and cannot occur.
Throwing Dices
When throwing a dice, there are 6 possible outcomes:
Example:
<!DOCTYPE html>
<html>
<body>
<h1>Machine Learning</h1>
<p>The possibility of throwing 3 fours at the same time is:</p>
<div id="demo"></div>
<script>
let p = Math.pow(1/6, 3);
document.getElementById("demo").innerHTML = p;
</script>
</body>
</html>
The possibility of throwing 3 likes at the same time is 6 times larger:
(lands on 1) + (Lands on 2) + ... + (Lands on 6)
Example:
<!DOCTYPE html>
<html>
<body>
<h1>Machine Learning</h1>
<p>The possibility of throwing 3 equal dices is:</p>
<div id="demo"></div>
<script>
let p = Math.pow(1/6, 3) * 6;
document.getElementById("demo").innerHTML = p;
</script>
</body>
</html>
6 Balls
Sample space = {(H, H, H), (H, H, T),(H, T, H), (T, H, H), (T, T, H), (T, H, T), (H, T, T), (T, T,
T)}.
P(3T) = P(0 H) = Number of outcomes with three tails/ Total Number of outcomes = 1/8
3. Probability of Cards
Spades, clubs, diamonds, and hearts make up the four suits that form a deck of 52 playing
cards. There are a total of 52 cards, with 13 in each of the four suits (clubs, diamonds,
hearts, and spades). The symbols for the cards are listed below.
Probability Examples and Solutions
We have provided you with some probability problems with their solutions.
Problem 1. There are 8 balls in a container, 4 are red, 1 is yellow and 3 are blue. What is the
probability of picking a yellow ball?
Solution:
The probability is equal to the number of yellow balls in the container divided by the total
number of balls in the container, i.e. 1/8.
Problem 2: A dice is rolled. What is the probability that an even number has been obtained?
Solution:
When fair six-sided dice are rolled, there are six possible outcomes: 1, 2, 3, 4, 5, or 6.
Out of these, half are even (2, 4, 6) and half are odd (1, 3, 5). Therefore, the probability of
getting an even number is:
P(even) = number of even outcomes / total number of outcomes
P(even) = 3 / 6
P(even) = ½
Problem 3. A bag contains 4 white, 5 red, and 6 blue balls. Three balls are drawn
at random from the bag. The probability that all of them are red, is:
Solution:
Let S be the sample space.
Then, n(S) = Number of ways of drawing 3 balls out of 15
= 15C3 = 455
Let E = event of getting all the 3 red balls.
n(E) = 5C3 = 10
P(E) = n(E)/n(S) = 10/455 = 2/91.
Problem 4. In a class there are 10 girls and 15 boys, what is the probability that 1
girl and 2 boys are selected?
Solution:
Let S be the sample space.
Then, n(S)= Number of ways of selecting 3 children out of 25
= 25C3
= 2300.
Let E= event of selecting 1 girl and 2 boys.
n(E) = 10C1*15C2 = 1050
P(E) = n(E)/n(S) = 1050/2300 = 21/46.
CALCULUS
What is Calculus?
Calculus, a branch of mathematics that deals with the study of rate of change. It was
founded by Newton and Leibniz.
Calculus math is commonly used in mathematical simulations to find the best solutions. It
focuses on core ideas like limits, functions, integration, differentiation, and so on.
Calculus mathematics is classified into two parts:
Differential Calculus: used to determine the rate of change
Integral Calculus: used to find quantity based on known rates of change.
Differential Calculus
Differential calculus is used to solve the problem of calculating the rate at which a
function changes in relation to other variables.
To obtain the optimal answer, derivatives are utilized to determine a function’s maxima
and minima values.
It primarily handles variables like x and y, functions like f(x), and the variations in x
and y that follow.
dy and dx are used to symbolize differentials.
The process of differentiating allows us to compute derivatives. The derivative of a
function is given by dy/dx or f’ (x).
1. Limits
2. Derivatives
Integral Calculus
The study of integrals and their properties is known as integral calculus. It is primarily useful
for:
To compute f from f’ (i.e. from its derivative). If a function f is differentiable in the
range under consideration, then f’ is specified in that range.
To determine the region under a curve.
Integration
Integration is exactly the opposite of differentiation. Differentiation is the partition of a
portion into a number of smaller parts, and integration is gathering tiny parts to create a
whole. It is frequently applied to area calculations.
Definite Integral
A definite integral has a specified boundary beyond which the equation must be computed.
The lower and upper limits of a function’s independent variable are defined, and its
integration is represented using definite integrals.
Indefinite Integral
An infinite integral lack a fixed boundary, i.e. there is no upper and lower limit. As a result,
the integration value is always followed by a constant value.