MLearning
/
Numpy
- 1 Supervised ML 4
-
Classifier S
-
Linear model S
-
Basis expansion S
-
Regularization S
- 2 Matplotlib 2
-
Subplots S
-
Pyplot S
- 3 Datasets 4
-
Iris species S
-
Diabetes S
-
Breast cancer S
-
Simulated data S
- 4 Numpy 7
-
Matrices S
-
Sparse matrices S
-
Vectorize S
-
Average S
-
Standard deviation S
-
Reshape S
-
Multiplication S
- 5 Pandas 5
-
Read data S
-
Data cleaning S
-
Find values S
-
Group rows S
-
Merge data S
- 6 Calculus 2
-
Derivatives S
-
Integrals S
- 7 Algorithms 3
-
K nearest neighbors S
-
Linear regression S
-
Gradient descent S
S
R
Q
ML Numpy Standard Deviation
High variance, data are larged spread Low variannce, data are clustered A = np.var(matrix) B = np.std(matrix)
Standard Deviation
p08 Variance is a measure of the spread of the data.
""" Variance and Standard deviation
Variance is a measure of the spread of the data.
A high variance means that data are spread over a large range.
A low variannce means that data are clustered close together.
Standard deviation is a measure of the spread of the data
that is more intuitive than variance, as it is expressed
in the same units as data.
"""
import numpy as np
A = np.array([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
])
B = np.array([
[1, 2, 3],
[4, 5, 6],
[7, 8, 900],
])
print(np.var(A)) # 6.666666666666667
print(np.std(A)) # 2.581988897471611
print()
print(np.var(B)) # 79206.66666666667
print(np.std(B)) # 281.43678982440565
print()
# Variation algorithm
N = A.size
mean = np.mean(A)
variation = (1/N) * np.sum((A - mean)**2) # population variance
standard_deviation = np.sqrt(variation)
print(variation) # 6.666666666666666
print(standard_deviation) # 2.581988897471611
assert standard_deviation == np.std(A) # passed
assert variation.round(14) == np.var(A).round(14) # passed
➥ Questions
Last update: 48 days ago