Image : Z Test www.code.edureify.com
Image : Z Test www.code.edureify.com

With the growing advancement in technology and everything getting surrounded by certain data skills, the need for possession of these skills is growing day by day. You can learn all these data skill sets from Edureify, the best AI learning app. The best online coding courses here give you the opportunity to start from scratch and be an expert in that field within a few months.

Z Test in Hypothesis testing in Machine Learning

A statistical test called the Z test is run on data that roughly fits the normal distribution. For assessing hypotheses, the z test can be applied to proportions, two samples, or one sample. When the population variance is known, it determines whether or not the means of two big samples differ.

Depending on the parameters of the data, a z test can also be divided into left-tailed, right-tailed, and two-tailed hypothesis tests. Learn more about the z test, its calculation, the z test statistic, and how to conduct the test for differences in this article.

What isThe Z Test?

As long as the data has a normal distribution, a z test can be used to determine if the means of two populations differ or not. It is necessary to set up the null hypothesis, and the alternative hypothesis, and calculate the value of the z-test statistic for this reason. The z critical value serves as the basis for the decision criterion.

Definition of Z Test

A normal distribution population with independent data points and a sample size higher than or equal to 30 is subjected to a z test. When the population variance is known, it is used to determine if the means of two populations are equal to one another.

Testing Formula Z

In order to determine whether there is a difference between the means of two populations, the z test formula compares the z statistic with the z critical value. The z critical value separates the acceptance and rejection sections of the distribution graph in hypothesis testing. The null hypothesis can be rejected if the test statistic is within the rejection region; otherwise, it cannot be rejected. Below is the z-test formula for setting up the necessary hypothesis tests for a one-sample and two-sample z-test. Also, opt for the best online certified coding courses at Edureify for clear concepts. 

Z Test with One Sample

When the population standard deviation is known, a one-sample z test is performed to determine whether there is a discrepancy between the sample mean and the population mean.

The left-tail test:

The null hypothesis is H 0: = 0.

A different hypothesis is H 1: 0

Decision criteria: Reject the null hypothesis if the z statistic exceeds the z critical value.

Test of the right tail:

The null hypothesis is H 0: = 0.

An alternative hypothesis is H 1: > > 0

Decision Criteria: Reject the null hypothesis if the z statistic is greater than the z critical value.

Double-Tailed Test:

The null hypothesis is H 0: = 0.

A different hypothesis is H 1: 0

Decision Criteria: Reject the null hypothesis if the z statistic is greater than the z critical value.

Two Sample Z Test

To determine whether there is a difference between the means of two samples, a two-sample z test is utilised. The following is the formula for the z-test statistic:

z=(\s¯¯¯¯¯\sx\s1\s−\s¯¯¯¯¯\sx\s2\s)

−\s(\sμ\s1\s−\sμ\s2\s)

The sample mean, the population means, and population variance for the first sample are given as x 1, 1, and 2, respectively.

The sample mean, the population means, and the population variance for the second sample is given as x 2, 2, and 2 correspondingly.

Similar to the one-sample test, the two-sample z test can be set up. The means of the two samples will be compared using this test, nevertheless. As an illustration, the null hypothesis is valid now.

How is the Z Test Statistic Calculated- Example and Solution

Patient No. Patient sex Patient age group Patient BP before Patient BP after
1) Female 32-35 152 153
2) Female 32-35 133 134
3) Female 32-35 146 147
4) Female 32-35 147 148
5) Female 32-35 121 122
6) Female 32-35 120 121
7) Female 32-35 134 135
8) Female 32-35 124 125
9) Female 32-35 124 125
10) Female 32-35 123 124
11) Female 32-35 167 168
12) Female 32-35 145 146
13) Female 32-35 132 133
14) Female 32-35 131 132
15) Female 32-35 130 133
16) Female 32-35 153 134
17) Female 32-35 163 124
18) Female 32-35 164 156
19) Female 32-35 165 134

 

Code:- 

import pandas as pd
from statsmodels.stats import weightstats as stests
dataframe = pd.read_csv(r"C:\Users\PARUL\Desktop\BP.csv")
dataframe[['patient_bp_before','patient_bp_after']].describe()
z test ,propability_value = tests.z test(dataframe['patient_bp_before'], x2=None, value=146)
print(float(propability_value))
if propability_value<0.05:
print("Null hypothesis rejected , Alternative hypothesis accepted")
else:
print("Null hypothesis accepted

Output:- 
In (15) runfile (C:users/Parul/Alternative Hypothesis accepted)

The Z test is an important part of Machine learning statistics. The coding courses online offer insights on the other topics such as:-

Some Frequently Asked Questions

Q:-What is the null hypothesis for the z-test?

Ans:- A two-proportion z-test allows you to compare two proportions to see if they are the same. The null hypothesis (H0) for the test is that the proportions are the same. The alternate hypothesis (H1) is that the proportions are not the same.

Q:- When should you use the z-test?

Ans:- If the population standard deviation is unknown, Z-test is recommended to be used. If the population standard deviation is known, then, the size of the sample does determine which test can be used: If the size is smaller than 30, a T-test is recommended to be used.

Q:- Why z-test is used in research?

Ans:-Z-test is performed in studies where the sample size is larger, and the variance is known. It is also used to determine if there is a significant difference between the mean of two independent samples.

Q:- How do you find a z-test example?

Ans:- A random sample of 19 women gained an average of 5.6 pounds. Test the hypothesis that the average weight gain per woman for the month was over 5 pounds. The standard deviation for all women in the group was 7.1. Z = 5.6 – 5 / (7.1/√19) = 1.345

Facebook Comments