It is a statistical test used to compare a sample distribution with a reference probability distribution, or to compare two sample distributions, to check if they differ significantly.
Click to reveal answer
beginner
What does the KS test statistic represent?
The KS test statistic is the maximum distance between the cumulative distribution functions (CDFs) of the two distributions being compared.
Click to reveal answer
beginner
In scipy, which function is used to perform the Kolmogorov-Smirnov test for one sample against a distribution?
The function is scipy.stats.kstest(). It compares a sample against a given distribution.
Click to reveal answer
beginner
What does a small p-value in the KS test indicate?
A small p-value means there is strong evidence that the sample distribution is different from the reference distribution.
Click to reveal answer
beginner
How do you interpret the KS test result when comparing two samples?
If the p-value is large, it suggests the two samples come from the same distribution; if small, they likely come from different distributions.
Click to reveal answer
What does the Kolmogorov-Smirnov test compare?
ATwo distributions or a sample against a distribution
BMeans of two samples
CVariances of two samples
DCorrelation between two variables
✗ Incorrect
The KS test compares the cumulative distributions of two samples or a sample and a reference distribution.
Which scipy function performs the KS test for one sample?
Ascipy.stats.ttest_1samp
Bscipy.stats.chisquare
Cscipy.stats.kstest
Dscipy.stats.ks_2samp
✗ Incorrect
scipy.stats.kstest compares one sample against a reference distribution.
What does a KS test statistic measure?
ADifference in means
BMaximum difference between CDFs
CSum of squared errors
DCorrelation coefficient
✗ Incorrect
The KS statistic is the largest vertical distance between two cumulative distribution functions.
If the KS test p-value is 0.01, what does it mean?
ADistributions are likely different
BDistributions are likely the same
CTest is inconclusive
DSample size is too small
✗ Incorrect
A small p-value (like 0.01) suggests strong evidence against the null hypothesis that distributions are the same.
Which test compares two samples directly using KS test?
Ascipy.stats.mannwhitneyu
Bscipy.stats.kstest
Cscipy.stats.ttest_ind
Dscipy.stats.ks_2samp
✗ Incorrect
scipy.stats.ks_2samp compares two independent samples using the KS test.
Explain how the Kolmogorov-Smirnov test works and what it measures.
Think about how you compare two shapes of data distributions.
You got /3 concepts.
Describe how to use scipy to perform a KS test on a sample against a normal distribution.
Remember the function name and what arguments it needs.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the scipy.stats.ks_2samp function in data analysis?
easy
A. To generate random numbers from a normal distribution
B. To calculate the mean of a dataset
C. To perform linear regression between two variables
D. To compare two samples and check if they come from the same distribution
Solution
Step 1: Understand the function purpose
ks_2samp is designed to compare two independent samples.
Step 2: Identify what it tests
It tests if the two samples come from the same continuous distribution.
Final Answer:
To compare two samples and check if they come from the same distribution -> Option D
Quick Check:
Kolmogorov-Smirnov test compares distributions [OK]
Hint: Remember KS test compares distributions, not means or regressions [OK]
Common Mistakes:
Confusing KS test with mean calculation
Thinking KS test performs regression
Assuming KS test generates random data
2. Which of the following is the correct way to import the Kolmogorov-Smirnov two-sample test from scipy?
easy
A. import ks_2samp from scipy.stats
B. import scipy.ks_2samp
C. from scipy.stats import ks_2samp
D. from scipy import ks_2samp
Solution
Step 1: Recall correct import syntax
Functions inside scipy.stats are imported using from scipy.stats import function_name.
Step 2: Match the function name
The function for KS two-sample test is ks_2samp, so the correct import is from scipy.stats import ks_2samp.
Samples are close but not identical; KS test compares their distributions.
Step 2: Run the KS test and check p-value
Running the code shows p-value approximately 0.999, indicating no strong evidence to reject similarity.
Final Answer:
0.999 -> Option A
Quick Check:
Close samples give very high p-value ~0.999 [OK]
Hint: Close samples usually yield high p-values, not moderate or low [OK]
Common Mistakes:
Assuming p-value is always very small for different samples
Confusing p-value with test statistic
Rounding errors leading to wrong choice
4. Identify the error in this code snippet that attempts to perform a KS test:
from scipy.stats import ks_2samp
sample1 = [1, 2, 3]
sample2 = [4, 5, 6]
result = ks_2samp(sample1)
print(result.statistic)
medium
A. Incorrect import statement for ks_2samp
B. Missing second sample argument in ks_2samp call
C. Using print instead of return to show result
D. Samples contain integers instead of floats
Solution
Step 1: Check function call parameters
ks_2samp requires two sample arguments, but only one is given.
Step 2: Identify the error cause
Missing second sample causes a TypeError because the function expects two inputs.
Final Answer:
Missing second sample argument in ks_2samp call -> Option B
Quick Check:
ks_2samp needs two samples [OK]
Hint: ks_2samp always needs two sample inputs [OK]
Common Mistakes:
Forgetting the second sample argument
Thinking print causes error
Assuming integer samples cause error
5. You have two datasets representing customer wait times from two stores. You want to check if their wait times differ significantly. Which approach using scipy is best?
hard
A. Use ks_2samp to compare the two samples' distributions
B. Calculate the mean wait time of each and compare with subtraction
C. Use linear regression to predict wait times from store ID
D. Use ttest_ind to compare the two samples assuming normality
Solution
Step 1: Understand the data and goal
We want to check if two samples (wait times) differ in distribution, not just means.
Step 2: Choose appropriate test
ks_2samp compares full distributions without assuming normality, ideal for wait times.
Step 3: Evaluate other options
Mean subtraction ignores distribution shape; regression is unrelated; ttest_ind assumes normality which may not hold.
Final Answer:
Use ks_2samp to compare the two samples' distributions -> Option A
Quick Check:
KS test compares distributions best for this case [OK]
Hint: KS test compares distributions without normality assumptions [OK]
Common Mistakes:
Using mean difference which ignores distribution shape
Applying t-test without checking normality
Using regression for distribution comparison
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.