KS Test is used to check if two continuous distributions follow the same distribution or not. Below is the Python code for performing KS Test.
# Import Libraries
import numpy as np
import seaborn as sns
from scipy import stats
import matplotlib.pyplot as plt
#Generating Normal Random Variable X
x = stats.norm.rvs(size= 100)
#Draw Kernel Density Estimation Plot for X
sns.kdeplot(np.array(x),bw = 0.5)
#Use kstest function available under scipy to compare X with Normal Distribution.
P-value is higher than the Significance level(Also known as Alpha .05 in our case) so we accept the Null Hypothesis which implies x is normally distributed.
Follow us to get more such articles.