numpy - Two-sample Kolmogorov-Smirnov Test in Python Scipy -
i can't figure out how two-sample ks test in scipy.
after reading documentation scipy kstest
i can see how test distribution identical standard normal distribution
from scipy.stats import kstest import numpy np x = np.random.normal(0,1,1000) test_stat = kstest(x, 'norm') #>>> test_stat #(0.021080234718821145, 0.76584491300591395) which means @ p-value of 0.76 can not reject null hypothesis 2 distributions identical.
however, want compare 2 distributions , see if can reject null hypothesis identical, like:
from scipy.stats import kstest import numpy np x = np.random.normal(0,1,1000) z = np.random.normal(1.1,0.9, 1000) and test whether x , z identical
i tried naive:
test_stat = kstest(x, z) and got following error:
typeerror: 'numpy.ndarray' object not callable is there way two-sample ks test in python? if so, how should it?
thank in advance
you're using one-sample ks test. want ks_2samp:
>>> scipy.stats import ks_2samp >>> import numpy np >>> >>> np.random.seed(12345678) >>> x = np.random.normal(0, 1, 1000) >>> y = np.random.normal(0, 1, 1000) >>> z = np.random.normal(1.1, 0.9, 1000) >>> >>> ks_2samp(x, y) ks_2sampresult(statistic=0.022999999999999909, pvalue=0.95189016804849647) >>> ks_2samp(x, z) ks_2sampresult(statistic=0.41800000000000004, pvalue=3.7081494119242173e-77)
Comments
Post a Comment