## How to Fit a Curve to Power-law Distributed Data in Python

In this tutorial, you’ll learn how to generate synthetic data that follows a power-law distribution, plot its cumulative distribution function (CDF), and fit a power-law curve to this CDF using Python. This process is useful for analyzing datasets that follow power-law distributions, which are common in natural and social phenomena. Prerequisites Ensure you have Python … Read more

## Sample a Random Number from a Probability Distribution in Python

Problem Formulation Challenge: Given a list. How will you select a number randomly from the list using probability distribution? When you select a number randomly from a list using a given probability distribution, the output number generated will be a number returned based on the relative weights (probability) of the given numbers. Let’s try to … Read more

## Factorials – NumPy, Scipy, Math, Python

Factorial Definition and Example 💡 The factorial function n! calculates the number of permutations in a set. Say you want to rank three soccer teams Manchester United, FC Barcelona, and FC Bayern München — how many possible rankings exist? The answer is 3! = 3 x 2 x 1 = 6. Practical Example: Say, there … Read more

## Normal Distribution and Shapiro-Wilk Test in Python

Normal distribution is a statistical prerequisite for parametric tests like Pearson’s correlation, t-tests, and regression. Testing for normal distribution can be done visually with sns.displot(x, kde=true). The Shapiro-Wilk test for normality can be done quickest with pingouin‘s pg.normality(x). 💡 Note: Several publications note that normal distribution is the least important prerequisite for parametric tests and … Read more

## Pearson Correlation in Python

A good solution to calculate Pearson’s r and the p-value, to report the significance of the correlation, in Python is scipy.stats.pearsonr(x, y). A nice overview of the results delivers pingouin’s pg.corr(x, y).  What is Pearson’s “r” Measure? A statistical correlation with Pearson’s r measures the linear relationship between two numerical variables. The correlation coefficient r … Read more

## How to Calculate z-scores in Python?

The z-scores can be used to compare data with different measurements and for normalization of data for machine learning algorithms and comparisons. 💡 Note: There are different methods to calculate the z-score. The quickest and easiest one is: scipy.stats.zscore(). What is the z-score? The z-score is used for normalization or standardization to make differently scaled … Read more

## How to Calculate a Logistic Sigmoid Function in Python?

Summary: You can caculate the logistic sigmoid function in Python using: Problem: Given a logistic sigmoid function: If the value of x is given, how will you calculate F(x) in Python? Let’s say x=0.458. 💡 Note: Logistic sigmoid function is defined as (1/(1 + e^-x)) where x is the input variable and represents any real … Read more

## How to Install SciPy on PyCharm?

SciPy is an open-source Python library for math, science, and engineering. It includes the wildly popular NumPy and Matplotlib libraries. Problem Formulation: Given a PyCharm project. How to install the SciPy library in your project within a virtual environment or globally? Here’s a solution that always works: Open File > Settings > Project from the … Read more

## Python – Inverse of Normal Cumulative Distribution Function (CDF)

Problem Formulation How to calculate the inverse of the normal cumulative distribution function (CDF) in Python? Method 1: scipy.stats.norm.ppf() In Excel, NORMSINV is the inverse of the CDF of the standard normal distribution. In Python’s SciPy library, the ppf() method of the scipy.stats.norm object is the percent point function, which is another name for the … Read more

## Best 10 Scipy Cheat Sheets

Hey Finxters! Another 10 of the best cheat sheets is here for you to peruse and hang on your wall with your other Python cheat sheets on the wall! Today, we are going to browse cheat sheets for Scipy!! For a quick explanation, SciPy is a scientific computation library that uses NumPy underneath. SciPy stands … Read more

## Python Scipy signal.find_peaks() — A Helpful Guide

This article deals with the analysis and processing of signals, more specifically on how to identify and calculate the peaks contained in a given signal. Motivation Being able to identify and hence work with the peaks of a signal is of fundamental importance in lots of different fields, from electronics to data science and economics. … Read more

## Fitting Data With Scipy’s UnivariateSpline() and LSQUnivariateSpline()

This article explores the use of the functions .UnivariateSpline() and .LSQUnivariateSpline(), from the Scipy package. What Are Splines? Splines are mathematical functions that describe an ensemble of polynomials which are interconnected with each other in specific points called the knots of the spline. They’re used to interpolate a set of data points with a function … Read more