"""Z-test:
Hypothesis Question: Is the mean of a sample significantly different from a
known population mean?
Example: Is the mean weight of a sample of students different from the population mean weight of 65 kg?
Python Code:"""
import scipy.stats as stats
# Sample data
sample_data = [...] # Insert your sample data here
pop_mean = 65 # Population mean
# Perform one-sample z-test
z_statistic, p_value = stats.ztest(sample_data, value=pop_mean)
print("Z-statistic:", z_statistic)
print("P-value:", p_value)
import numpy as np
def calculate_z_score(data):
# Mean of the dataset
mean = np.mean(data)
# Standard Deviation of tha dataset
std_dev = np.std(data)
# Z-score of tha data points
z_scores = (data - mean) / std_dev
return z_scores
# Example dataset
dataset = [3,9, 23, 43,53, 4, 5,30, 35, 50, 70, 150, 6, 7, 8, 9, 10]
z_scores = calculate_z_score(dataset)
print('Z-Score :',z_scores)
# Data points which lies outside 3 standard deviatioms are outliers
# i.e outside range of99.73% values
outliers = [data_point for data_point, \
z_score in zip(dataset, z_scores) if z_score > 3]
print(f'\nThe outliers in the dataset is {outliers}')