Hypothesentests in Python
James Chapman
Curriculum Manager, DataCamp

Kontrollgruppe:

Treatment:

import pandas as pd
print(stack_overflow)
respondent age_1st_code ... age hobbyist
0 36.0 30.0 ... 34.0 Yes
1 47.0 10.0 ... 53.0 Yes
2 69.0 12.0 ... 25.0 Yes
3 125.0 30.0 ... 41.0 Yes
4 147.0 15.0 ... 28.0 No
... ... ... ... ... ...
2259 62867.0 13.0 ... 33.0 Yes
2260 62882.0 13.0 ... 28.0 Yes
[2261 rows x 8 columns]
Eine Hypothese:
Der mittlere Jahreslohn der Population von Data Scientists beträgt 110.000 $
Punktschätzer (Stichprobenstatistik):
mean_comp_samp = stack_overflow['converted_comp'].mean()
119574.71738168952
import numpy as np# Schritt 3. Schritte 1 & 2 oft wiederholen und anhängen so_boot_distn = [] for i in range(5000): so_boot_distn.append(# Schritt 2. Punktschätzer berechnen np.mean(# Schritt 1. Neu ziehen (Resampling) stack_overflow.sample(frac=1, replace=True)['converted_comp']))
import matplotlib.pyplot as plt
plt.hist(so_boot_distn, bins=50)
plt.show()

std_error = np.std(so_boot_distn, ddof=1)
5607.997577378606
$\text{standardized value} = \dfrac{\text{value} - \text{mean}}{\text{standard deviation}}$
$z = \dfrac{\text{sample stat} - \text{hypoth. param. value}}{\text{standard error}}$
$z = \dfrac{\text{sample stat} - \text{hypoth. param. value}}{\text{standard error}}$
stack_overflow['converted_comp'].mean()
119574.71738168952
mean_comp_hyp = 110000
std_error
5607.997577378606
z_score = (mean_comp_samp - mean_comp_hyp) / std_error
1.7073326529796957
Prüfen, ob Stichprobenstatistiken nahe bei oder weit weg von erwarteten (bzw. „hypothetischen“) Werten liegen
Standardnormalverteilung: Normalverteilung mit Mittelwert = 0 und Standardabweichung = 1

Hypothesentests in Python