# Using KStests to find my estimator is a good fit with my distribution

I am trying to build an estimator based on my distribution that has 1585 values in it. The distribution itself kinda looks normal so I created a KDE and MLE estimators to find the best fit for my distribution.

KDE Estimate:

density = kde.gaussian_kde(odu, bw_method=None)


MLE

alpha = norm.fit(odu)
beta = norm.fit(odu)
e = norm(alpha,beta)


After running KS test for both, I get these values: (Note odu is the dataframe I am comparing too).

KDE KS Test

kstest(odu,density)


output:

KstestResult(statistic=0.9999938489747389, pvalue=0.0)


MLE kstest

kstest(odu,e.cdf)


Output:

KstestResult(statistic=0.11133223603089792, pvalue=3.9032020068459515e-17)


I am confused with the output kstest gives for both values. Lower the p-value means the null hypothesis is false, that means the distribution is a good fit? My professor says D-value close to 1 means its a good fit and the lower p-value means it has a high level of confidence. Is this correct? Thank you • Neither you nor your professor express the problem in a precisely correct way. But if the p-value is low, below a significance level that you choose means that you reject the null hypothesis that the two distributions are the same. That means that you have a good fit. So you are right in that regard. Your Professor is wrong. A large value of the test statistic D indicates a poor fit. It corresponds to a low p-value. Technically we say that if the p-value is above the significance level we can't reject the null hypothesis. – Michael R. Chernick Oct 22 '19 at 19:05
• Awesome thank you! Quick question, should I use cdf or pdf in kstests? – Tyler Oleson Oct 22 '19 at 19:31
• The Kolmogorov-Sminrnov test uses the cumulative distribution for a known hypothesized distribution & the empiric cumulative distribution for the sample distribution based on your data. It does not involve probability density functions. – Michael R. Chernick Oct 22 '19 at 19:35
• It's not okay to use a Kolmogorov-Smirnov test to test the fit of a density estimate to the sample you estimated it from; the Kolmogorov-Smirnov test assumes a completely specified distribution, not an estimated one. – Glen_b -Reinstate Monica Oct 23 '19 at 5:12