Introduction and Topic Overview

Welcome! Today, we're going to explore Scipy, a library in Python designed for advanced mathematical and statistical computing—an extension of Numpy. One of the most significant advantages of using a powerful computing tool like Scipy is its ability to tackle complex problems that require numerous calculations, a feature which is crucial in fields such as engineering and data science, or any discipline that relies heavily on data analysis. By the end of this lesson, you'll be introduced to various useful features in Scipy, which will serve as additional tools in your data analytics toolbox.

Installing and Importing Scipy

Scipy comes pre-installed in most CodeSignal IDEs. Let's import the stats module, which provides numerous statistical functions:

from scipy import stats
Accessing Distribution Functions in Scipy

In statistics, distribution functions play a crucial role—they enable us to identify the probability of potential outcomes of a random event. For instance, in a dice game, the distribution function can inform us of the chances of rolling a six. As we need some data to explore Scipy, let's firstly look at one way of generating meaningful data sample. We can utilise numpy.random module here:

import numpy as np

# Simulating temperature data for a year in a city
temp_data = np.random.normal(loc=30, scale=10, size=365)

In this scenario, we generate an array of 365 values, which are normally distributed with mean=30 and std=10. Note, that in numpy random, loc stands for mean, and scale stands for std.

Using Descriptive Statistics Functions in Scipy

Scipy offers more statistical functions than Numpy. We'll explore two: skewness and kurtosis. Skewness measures the asymmetry of a probability distribution around its mean, while kurtosis gauges how outlier-prone a distribution is. For instance, these metrics could help us understand unusual variations in a city's annual temperature data.

data = np.random.normal(size=1000)

# Compute skewness - a measure of data asymmetry
data_skewness = stats.skew(data)

# Compute kurtosis - a measure of data "tailedness" or outliers
data_kurtosis = stats.kurtosis(data)

print(f"Skewness: {data_skewness}\nKurtosis: {data_kurtosis}")
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal