Non-parametric tests are applied in hypothesis testing when the data does not satisfy the assumptions necessary for parametric tests, such as normality or equal variances. These tests are especially helpful for analyzing ordinal data, small sample sizes, or data with outliers.
Common Non-Parametric Tests
Lets see some commonly used non-parametric tests,
1. Mann-Whitney U Test
- The Mann-Whitney U test is a non-parametric alternative to the independent t-test. It assesses whether there is a difference between two independent groups on a continuous or ordinal variable.
- If we want to compare two independent groups, the Mann-Whitney U test is an excellent choice as it assesses whether two groups have different distributions.
Lets see an example of customer satisfaction score,
Python
import numpy as np
import scipy.stats as stats
region_a = [85, 88, 90, 92, 95]
region_b = [78, 80, 83, 85, 87]
stat, p_value = stats.mannwhitneyu(region_a, region_b, alternative='two-sided')
print(f"U-statistic: {stat}, p-value: {p_value}")
Output
U-statistic: 23.5, p-value: 0.02780296243469296
Since the p-value is less than 0.05, we reject the null hypothesis, indicating a significant difference between the two regions.
2. Wilcoxon Signed-Rank Test
- The Wilcoxon signed-rank test is used for comparing two related samples to assess whether their population mean ranks differ. It's the non-parametric counterpart to the paired t-test.
- When comparing two related samples, the Wilcoxon Signed-Rank test should be used, as it evaluates the difference in ranks for paired data.
Lets understand it with an example showing the evaluation of a Training program,
Python
pre_training = [78, 82, 85, 88, 92]
post_training = [82, 85, 88, 90, 94]
stat, p_value = stats.wilcoxon(pre_training, post_training)
print(f"Statistic: {stat}, p-value: {p_value}")
Output
Statistic: 0.0, p-value: 0.0625
The output suggests there is no significant difference due to the training program.
3. Shapiro-Wilk Test
- The Shapiro-Wilk test is used to check if a sample comes from a normally distributed population. It's particularly useful for small sample sizes.
- To check for normality in small samples, we use the Shapiro-Wilk test, which is sensitive to deviations from normality.
Lets see an example of testing normality of data,
Python
data = np.random.normal(loc=0, scale=1, size=100)
stat, p_value = stats.shapiro(data)
print(f"Shapiro-Wilk statistic: {stat}, p-value: {p_value}")
Output
Shapiro-Wilk statistic: 0.9837449032862893, p-value: 0.2569742070326989
The output suggests the sample follows a normal distribution.
4. Anderson-Darling Test
- The Anderson-Darling test is used to check if a sample comes from a specified distribution (e.g., normal distribution). It gives more weight to the tails of the distribution than other tests, such as the Kolmogorov-Smirnov test.
- A test for normality that is more sensitive to tail deviations than the Kolmogorov-Smirnov test, ideal for checking if a sample follows a specific distribution.
Lets see normality testing example,
Python
data = np.random.normal(loc=0, scale=1, size=100)
result = stats.anderson(data, dist='norm')
print(
f"Statistic: {result.statistic}, Critical values: {result.critical_values}")
Output
Statistic: 0.3747489555840531, Critical values: [0.555 0.632 0.759 0.885 1.053]
Since the test statistic is less than the critical value, we fail to reject the null hypothesis, suggesting the data follows the normal distribution.
5. Kruskal-Wallis H Test
- The Kruskal-Wallis H test is a non-parametric method for testing whether samples originate from the same distribution. It's used when comparing more than two independent groups.
- When dealing with more than two independent groups, the Kruskal-Wallis H test provides an appropriate non-parametric alternative to ANOVA.
Lets see an example of comparing test scores across multiple teaching methods,
Python
method_a = [88, 90, 92, 94, 96]
method_b = [78, 80, 82, 84, 86]
method_c = [85, 87, 89, 91, 93]
stat, p_value = stats.kruskal(method_a, method_b, method_c)
print(f"H-statistic: {stat}, p-value: {p_value}")
Output
H-statistic: 9.620000000000005, p-value: 0.008147859697679966
Since p-value less than 0.05, at least one teaching method differs significantly.
6. Friedman Test
- The Friedman test is a non-parametric test for detecting differences in treatments across multiple test attempts. It's used for repeated measures on the same subjects.
- In cases of repeated measures, where the same subjects are tested under different conditions, the Friedman test is an ideal choice.
Lets see an example comparing ratings of different products by the same group,
Python
product_1 = [4, 5, 4, 3, 5]
product_2 = [3, 4, 3, 4, 4]
product_3 = [5, 5, 5, 5, 5]
stat, p_value = stats.friedmanchisquare(product_1, product_2, product_3)
print(f"Statistic: {stat}, p-value: {p_value}")
Output
Statistic: 7.111111111111117, p-value: 0.0285655007845503
The output indicates a significant difference in ratings.
7. Kolmogorov-Smirnov Test
- The Kolmogorov-Smirnov (KS) test compares a sample with a reference probability distribution or two samples. It's often used to test whether a sample follows a specified distribution (e.g., normal distribution) or to compare two samples for differences in their distributions.
- If we're comparing two distributions or testing the goodness-of-fit of a sample to a known distribution, the Kolmogorov-Smirnov test is appropriate due to its flexibility in comparing sample distributions.
Lets see an example of comparing sample distribution to normal distribution,
Python
import numpy as np
import scipy.stats as stats
data = np.random.normal(loc=0, scale=1, size=100)
stat, p_value = stats.kstest(data, 'norm')
print(f"KS-statistic: {stat}, p-value: {p_value}")
Output
KS-statistic: 0.08648372023957773, p-value: 0.4194177770213061
Since p-value is greater than 0.05, the sample follows normal distribution.
8. Lilliefors Test
- The Lilliefors test is a variant of the Kolmogorov-Smirnov test and is used for testing the normality of data. It's particularly useful when the parameters of the normal distribution (mean and variance) are unknown.
- If we have large datasets, the Lilliefors test might be preferred as it is more robust when parameters are unknown.
Lets see a Testing normality example,
Python
from statsmodels.stats.diagnostic import lilliefors
data = np.random.normal(loc=0, scale=1, size=100)
stat, p_value = lilliefors(data)
print(f"Lilliefors statistic: {stat}, p-value: {p_value}")
Output
Lilliefors statistic: 0.11077802859590069, p-value: 0.00429933056976003
The output indicates the sample is not normally distributed.
Similar Reads
Introduction to AI
What is Artificial Intelligence (AI)Artificial Intelligence (AI) is a technology that enables machines and computers to perform tasks that typically require human intelligence. It helps systems learn from data, recognize patterns and make decisions to solve complex problems. It is used in healthcare, finance, e-commerce and transporta
10 min read
Types of Artificial Intelligence (AI)Artificial Intelligence refers to something which is made by humans or non-natural things and Intelligence means the ability to understand or think. AI is not a system but it is implemented in the system. There are many different types of AI, each with its own strengths and weaknesses.This article w
6 min read
Types of AI Based on FunctionalitiesArtificial Intelligence (AI) has become central to applications in healthcare, finance, education and many more. However, AI operates differently at various levels based on how it processes data, learns and responds. Classifying AI by its functionalities helps us better understand its current capabi
4 min read
Agents in AIAn artificial intelligence (AI) agent is a software program that can interact with its environment, collect data and use that data to perform self-directed tasks that meet predetermined goals. Humans set goals, but an AI agent independently chooses the best actions it needs to perform to achieve tho
7 min read
Artificial intelligence vs Machine Learning vs Deep LearningNowadays many misconceptions are there related to the words machine learning, deep learning, and artificial intelligence (AI), most people think all these things are the same whenever they hear the word AI, they directly relate that word to machine learning or vice versa, well yes, these things are
4 min read
Problem Solving in Artificial IntelligenceProblem solving is a fundamental concept in artificial intelligence (AI) where systems are designed to identify challenges, make decisions and find efficient solutions. AI uses agents which are systems that perceive their environment and take actions to achieve specific goals. They go beyond simple
6 min read
Top 20 Applications of Artificial Intelligence (AI) in 2025Artificial Intelligence is the practice of transforming digital computers into working robots. They are designed in such a way that they can perform any dedicated tasks and also take decisions based on the provided inputs. The reason behind its hype around the world today is its act of working and t
13 min read
AI Concepts
Search Algorithms in AISearch algorithms in AI help find solutions by exploring possible paths or options in a problem space. AI uses them in tasks like pathfinding, decision making and game playing. These algorithms work by searching through a set of possibilities to reach a goal, either blindly without extra information
6 min read
Local Search Algorithm in Artificial IntelligenceLocal search algorithms are important in artificial intelligence as they can quickly find good answers, especially when finding the perfect solution would take too long or too much effort. They are useful for big or complex problems where checking every possible option isn't practical.It focus only
7 min read
Adversarial Search Algorithms in Artificial Intelligence (AI)Adversarial search algorithms are the backbone of strategic decision-making in artificial intelligence, it enables the agents to navigate competitive scenarios effectively. This article offers concise yet comprehensive advantages of these algorithms from their foundational principles to practical ap
15+ min read
Constraint Satisfaction Problems (CSP) in Artificial IntelligenceA Constraint Satisfaction Problem is a mathematical problem where the solution must meet a number of constraints. In CSP the objective is to assign values to variables such that all the constraints are satisfied. Many AI applications use CSPs to solve decision-making problems that involve managing o
10 min read
Knowledge Representation in AIknowledge representation (KR) in AI refers to encoding information about the world into formats that AI systems can utilize to solve complex tasks. This process enables machines to reason, learn, and make decisions by structuring data in a way that mirrors human understanding.Knowledge Representatio
9 min read
First-Order Logic in Artificial IntelligenceFirst-Order Logic (FOL) also known as predicate logic helps us represent knowledge, reason through problems and understand language. By building on propositional logic and adding quantifiers and predicates, FOL allows us to express more complex relationships and make decisions based on logical reaso
4 min read
Reasoning Mechanisms in AIArtificial Intelligence (AI) systems are designed to mimic human intelligence and decision-making processes, and reasoning is a critical component of these capabilities. Reasoning Mechanism in AI involves the processes by which AI systems generate new knowledge from existing information, make decisi
9 min read
Machine Learning in AI
Robotics and AI
Artificial Intelligence in RoboticsArtificial Intelligence (AI) in robotics is one of the most groundbreaking technological advancements, revolutionizing how robots perform tasks. What was once a futuristic concept from space operas, the idea of "artificial intelligence robots" is now a reality, shaping industries globally. Unlike ea
10 min read
What is Robotics Process AutomationImagine having a digital assistant that works tirelessly 24/7, never takes a break, and never makes a mistake. Sounds like a dream, right? This is the magic of Robotic Process Automation (RPA). Instead of humans handling repetitive, time-consuming tasks, RPA lets software robots step in to take over
8 min read
Automated Planning in AIAutomated planning is an essential segment of AI. Automated planning is used to create a set of strategies that will bring about certain results from a certain starting point. This area of AI is critical in issues to do with robotics, logistics and manufacturing, game playing as well as self-control
8 min read
AI in Transportation - Benifits, Use Cases and ExamplesAI positively impacts transportation by improving business processes, safety and passenger satisfaction. Applied on autopilot, real-time data analysis, and profit prediction, AI contributes to innovative and adaptive Autonomous car driving, efficient car maintenance, and route planning. This ranges
15+ min read
AI in Manufacturing : Revolutionizing the IndustryArtificial Intelligence (AI) is at the forefront of technological advancements transforming various industries including manufacturing. By integrating AI into the manufacturing processes companies can enhance efficiency, improve quality, reduce costs and innovate faster. AI in ManufacturinThis artic
6 min read
Generative AI
What is Generative AI?Generative AI is a type of artificial intelligence designed to create new content such as text, images, music or even code by learning patterns from existing data. Unlike traditional AI systems that primarily analyze or classify data, generative AI models like GPT (for text) or DALL·E (for images) c
7 min read
Generative Adversarial Network (GAN)Generative Adversarial Networks (GAN) help machines to create new, realistic data by learning from existing examples. It is introduced by Ian Goodfellow and his team in 2014 and they have transformed how computers generate images, videos, music and more. Unlike traditional models that only recognize
12 min read
Cycle Generative Adversarial Network (CycleGAN)Generative Adversarial Networks (GANs) use two neural networks i.e a generator that creates images and a discriminator that decides if those images look real or fake. Traditional GANs need paired data means each input image must have a matching output image. But finding such paired images is difficu
7 min read
StyleGAN - Style Generative Adversarial NetworksStyleGAN is a generative model that produces highly realistic images by controlling image features at multiple levels from overall structure to fine details like texture and lighting. It is developed by NVIDIA and builds on traditional GANs with a unique architecture that separates style from conten
5 min read
Introduction to Generative Pre-trained Transformer (GPT)The Generative Pre-trained Transformer (GPT) is a model, developed by Open AI to understand and generate human-like text. GPT has revolutionized how machines interact with human language making more meaningful communication possible between humans and computers. In this article, we are going to expl
7 min read
BERT Model - NLPBERT (Bidirectional Encoder Representations from Transformers) stands as an open-source machine learning framework designed for the natural language processing (NLP). The article aims to explore the architecture, working and applications of BERT. Illustration of BERT Model Use CaseWhat is BERT?BERT
12 min read
Generative AI Applications Generative AI generally refers to algorithms capable of generating new content: images, music, text, or what have you. Some examples of these models that originate from deep learning architectures-including Generative Adversarial Networks (GANs) and Variational Autoencoders (VAEs)-are revolutionizin
7 min read
AI Practice
Top Artificial Intelligence(AI) Interview Questions and Answers As Artificial Intelligence (AI) continues to expand and evolve, the demand for professionals skilled in AI concepts, techniques, and tools has surged. Whether preparing for an interview or refreshing your knowledge, mastering key AI concepts is crucial. This guide on the Top 50 AI Interview Question
15+ min read
Top Generative AI Interview Question with AnswerWelcome to the Generative AI Specialist interview. In this role, you'll lead innovation in AI by developing and optimising models to generate data, text, images, and other content, leveraging cutting-edge technologies to solve complex problems and advance our AI capabilities.In this interview, we wi
15+ min read
30+ Best Artificial Intelligence Project Ideas with Source Code [2025 Updated]Artificial intelligence (AI) is the branch of computer science that aims to create intelligent agents, which are systems that can reason, learn and act autonomously. This involves developing algorithms and techniques that enable machines to perform tasks that typically require human intelligence suc
15+ min read