This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |