Data Science With Python - Lesson 06 - Scientific Computing With Python (Scipy) - Ebook
Data Science With Python - Lesson 06 - Scientific Computing With Python (Scipy) - Ebook
Statistics
Platform integration
Mathematical equations
Scientific Domains
SciPy
SciPy has built-in packages that help in handling the scientific domains.
Mathematics
integration Statistics
(Normal distribution)
Linear algebra
Multidimensional
image processing
Mathematics Language
constants integration
SciPy and Its Characteristics
Integration IO
5
4
Introduction of SciPy Sub-Package
SciPy Sub-Package
cluster ndimage
Clustering algorithms N-dimensional image processing
constants odr
Physical and mathematical constant Orthogonal distance regression
fftpack optimize
Fast Fourier Transform routines Optimization and root-finding routines
integrate signal
Integration and ordinary differential equation solvers Signal processing
Spatial sparse
Spatial data structures and algorithms Sparse matrices and associated routines
interpolate weave
Interpolation and smoothing splines C/C++ integration
IO stats
Input and Output Statistical distributions and functions
special
linalg
Special functions
Linear algebra
SciPy Sub-Package: Integration
SciPy provides integration techniques that solve mathematical sequences and series, or
perform function approximation.
integrate.quad(f, a, b)
• integrate.dblquad()
• integrate.tplquad()
• integrate.nquad()
Perform multiple
integration using the
lambda built-in function
SciPy Sub-Package: Optimization
SciPy Sub-Package: Optimization
Optimization is a process to improve performance of a system mathematically by fine-tuning the process
parameters.
SciPy provides several optimization algorithms, such as bfgs, Nelder-Mead simplex, Newton Conjugate
Gradient, COBYLA, or SLSQP.
lower limit in a
given range
Perform optimize
minimize function
using bfgs method
and options
SciPy provides rapid linear algebra capabilities and contains advanced algebraic functions.
This function is used to compute the inverse of the given matrix. Let’s look at the inverse matrix
operation.
SciPy provides rapid linear algebra capabilities and contains advanced algebraic functions.
With this function you can compute the value of the determinant for the given matrix.
SciPy provides rapid linear algebra capabilities and contains advanced algebraic functions.
2x + 3 y + z = 21
-x + 5y + 4z = 9
3x + 2y + 9z = 6
Use solve
method
SciPy Sub-Package: Linear Algebra
SciPy provides rapid linear algebra capabilities and contains advanced algebraic functions.
Import linalg
Define matrix
U (Unitary matrix)
Sigma or square root of eigenvalues
Access: Click on the Practice Labs tab on the left side panel of the LMS. Copy or note the
username and password that is generated. Click on the Launch Lab button. On the page that
appears, enter the username and password in the respective fields, and click Login.
SciPy Sub-Package: Statistics
SciPy Sub-Package: Statistics
CDF or Cumulative Distribution Function provides the cumulative probability associated with a function.
One standard
Cumulative deviation
Age Range Frequency
Frequency
0-10 19 19
41-50 10 143
-3 -2 -1 01 1 2 3
51-60 17 160
F(x) = P(X≤x)
negative infinity
SciPy Sub-Package: Statistics
Probability Density Function, or PDF, of a continuous random variable is the derivative of its Cumulative Distribution
Function, or CDF.
Derivative of CDF
SciPy Sub-Package: Statistics
loc and scale are used to adjust the location and scale of the data distribution.
SciPy Sub-Package: Weave and IO
SciPy Sub-Package: Weave
The weave package provides ways to modify and extend any supported extension libraries.
The IO package provides a set of functions to deal with several kinds of file formats.
Problem Statement:
There is a test with 30 questions worth 150 marks. The test has two types of questions:
1. True or false – carries 4 marks each
2. Multiple choice – carries 9 marks each
Find the number of true or false and multiple-choice questions.
Common instructions:
•If you are new to Python, download the “Anaconda Installation Instructions” document
from the “Resources” tab to view the steps for installing Anaconda and the Jupyter
notebook.
•Download the “Assignment 01” notebook and upload it on the Jupyter notebook to
access it.
•Follow the cues provided to complete the assignment.
Using SciPy to Declare Random Values
Problem Statement:
Use SciPy to declare 20 random values for random values and perform the following:
1. CDF – Cumulative Distribution Function for 10 random variables.
2. PDF – Probability Density Function for 14 random variables.
Common instructions:
•If you are new to Python, download the “Anaconda Installation Instructions” document from the
“Resources” tab to view the steps for installing Anaconda and the Jupyter notebook.
•Download the “Assignment 02” notebook and upload it on the Jupyter notebook to access it.
•Follow the cues provided to complete the assignment.
Key Takeaways
Both the upper and lower limit values should be specified for optimize.curve.fit function.
Knowledge
Check
Which of the following function is used for inversing the matrix?
2
a. SciPy.special
b. SciPy.linalg
c. SciPy.signal
d. SciPy.stats
Knowledge
Check
Which of the following function is used for inversing the matrix?
2
a. SciPy.special
b. SciPy.linalg
c. SciPy.signal
d. SciPy.stats
a. Website
b. Plot data
c. Scientific calculations
d. System administration
Knowledge
Check
Which of the following is performed using SciPy?
3
a. Website
b. Plot data
c. Scientific calculations
d. System administration
SciPy has been specially made to perform scientific calculations. Generally, Python is the programming
language that has libraries to perform all listed activities.
Knowledge
Check
Which of the following functions is used to calculate minima?
4
a. optimize.minimize()
b. integrate.quad()
c. stats.linregress()
d. linalg.solve()
Knowledge
Check
Which of the following functions is used to calculate minima?
4
a. optimize.minimize()
b. integrate.quad()
c. stats.linregress()
d. linalg.solve()
The function optimize.minimize() is used to calculate minima. integrate.quad () is used for integral
calculation, stats.linregress() is used for linear regression, and linalg.solve() is used to solve a linear system.
Knowledge
Check
Which of the following syntaxes is used to generate 100 random variables from a
5 t-distribution with df = 10?
a. stats.t.pmf(df=10, size=100)
b. stats.t.pdf(df=10, size=100)
c. stats.t.rvs(df=10, size=100)
d. stats.t.rand(df=10, size=100)
Knowledge
Check
Which of the following syntaxes is used to generate 100 random variables from a
5 t-distribution with df = 10?
a. stats.t.pmf(df=10, size=100)
b. stats.t.pdf(df=10, size=100)
c. stats.t.rvs(df=10, size=100)
d. stats.t.rand(df=10, size=100)
The stats.t.rvs() function is used to generate random variables. stats.t.pmf() function is used to generate the
probability of mass function, and stats.t.pdf() is used to generate probability density function. Note that
stats.t.rand () does not exist.
Knowledge
Check
Which of the following functions is used to run C or C++ codes in SciPy?
6
a. io.loadmat()
b. weave.inline()
c. weave.blitz()
d. io.whosmat()
Knowledge
Check
Which of the following functions is used to run C or C++ codes in SciPy?
6
a. io.loadmat()
b. weave.inline()
c. weave.blitz()
d. io.whosmat()
inline() function accepts C codes as string and compiles them for later use. loadmat() loads variables from
.mat file. whosmat() checks the variables inside a .mat file.blitz(), and then compiles NumPy expressions for
faster running, but it can’t accept C codes.
Thank You