Skip to content

Instantly share code, notes, and snippets.

@sergeymong
sergeymong / pmf_plot.py
Created January 5, 2021 14:16
[PMF] Probability Mass Function #Python #Matplotlib #Numpy #Statistics
def plot_pmf(data, ylabel='pmf', xlabel='defaults'):
# Compute bin edges: bins
bins = np.arange(min(data), max(data) + 1.5) - 0.5
# Generate histogram
_ = plt.hist(data, bins=bins, normed=True)
# Label axes
_ = plt.ylabel(ylabel)
_ = plt.xlabel(xlabel)
@sergeymong
sergeymong / pearson.py
Created January 5, 2021 13:37
[Pearson correlation coefficient] Between two variables #Python #Numpy #EDA #Statistics
def pearson_r(x, y):
"""Compute Pearson correlation coefficient between two arrays."""
# Compute correlation matrix: corr_mat
corr_mat = np.corrcoef(x, y)
# Return entry [0,1]
return corr_mat[0,1]
@sergeymong
sergeymong / ecdf.py
Last active January 5, 2021 13:38
[ECDF] Empirical Cumulative Distribution Function #EDA #Python #Numpy
def ecdf(column: list[int]):
"""Compute ECDF for a one-dimensional array of measurements."""
# Number of data points: n
n = len(column)
# x-data for the ECDF: x
x = np.sort(column)
# y-data for the ECDF: y
y = np.arange(1, 1 + n) / n