Scientific computing with SciPy
23 steps in 8 sets of Python.
SciPy is what you use once NumPy runs out. Distributions and the hypothesis tests built on them come first, since that is what most people arrive for, followed by correlation and resampling.
Then the numerical methods: optimization, integration and interpolation, linear algebra and signal processing, and a last set on sparse matrices and spatial structures. Twenty-three steps, and the arithmetic is doing the same work a lot of graduate courses spend a term on.
Distributions
- DistributionsA frozen distribution answers pdf, cdf and ppf without repeating parameters.
- Discrete distributionsBinomial, Poisson and the questions they answer about counts.
- Describing a sampledescribe, trimmed means and robust spread in one place.
Hypothesis tests
- Comparing two meansThe t-test, and the variant that does not assume equal variances.
- When normality is doubtfulRank-based tests make fewer assumptions than a t-test.
- Categorical associationA contingency table, a chi-square test, and Fisher's exact for small counts.
- Comparing several groupsOne-way ANOVA, and the rank-based alternative when variances differ.
Correlation & resampling
- Correlation and simple regressionPearson for linear, Spearman for monotonic, linregress for the line.
- Bootstrapping a confidence intervalResampling gives an interval for any statistic, with no formula needed.
Optimization
- Minimizing a functionminimize walks downhill from a starting point, with or without gradients.
- Constrained optimizationBounds and constraints, and the linear-programming shortcut.
- Fitting a model to datacurve_fit finds the parameters, and the covariance gives their error.
- Finding rootsroot_scalar for one equation, root for a system, least_squares for a fit.
Calculus & interpolation
- Integrationquad for a definite integral, solve_ivp for a differential equation.
- InterpolationFilling in between samples: linear, cubic spline, or a smoothing fit.
Linear algebra & signals
- Linear algebrascipy.linalg goes beyond numpy: decompositions, matrix functions, solvers.
- Signal processingPeaks, filters and spectra over a sampled series.
- Fourier transformsrfft for real signals, fftfreq for the axis that makes it readable.
Sparse & spatial
- Sparse matricesWhen most entries are zero, store only the ones that are not.
- Graphs as sparse matricescsgraph treats a sparse adjacency matrix as a graph.
- Spatial queriesDistances, nearest neighbours and hulls over point sets.
- Hierarchical clusteringlinkage builds the tree, fcluster cuts it into groups.
Encore
- sp_fit_report.pyFit a learning curve, bootstrap its parameters, and test the residuals.