Created
October 16, 2023 11:04
-
-
Save saimadhu-polamuri/2bfb47a4baa3d6386836758f8d7e55ab to your computer and use it in GitHub Desktop.
This file contains 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
import numpy as np | |
from scipy.stats import ks_2samp | |
import matplotlib.pyplot as plt | |
# Generate two random samples | |
np.random.seed(123) | |
sample1 = np.random.normal(loc=0, scale=1, size=100) | |
sample2 = np.random.normal(loc=1, scale=1, size=100) | |
# Compute the test statistic and p-value | |
statistic, pvalue = ks_2samp(sample1, sample2) | |
# Print the results | |
print("Kolmogorov-Smirnov test results:") | |
print(f"Statistic: {statistic:.3f}") | |
print(f"P-value: {pvalue:.3f}") | |
# Visualize the two samples and the test statistic | |
fig, ax = plt.subplots() | |
ax.hist(sample1, alpha=0.5, label="Sample 1") | |
ax.hist(sample2, alpha=0.5, label="Sample 2") | |
ax.axvline(np.max(sample1), color="red", linestyle="--", label="Test Statistic") | |
ax.legend() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment