t-टेस्ट करना

Python में Hypothesis Testing

James Chapman

Curriculum Manager, DataCamp

दो-सैंपल समस्याएँ

  • किसी वैरिएबल के समूहों में सैंपल आँकड़ों की तुलना करें
  • converted_comp एक संख्यात्मक वैरिएबल है
  • age_first_code_cut एक श्रेणीबद्ध वैरिएबल है, जिसके लेवल ("child" और "adult") हैं
  • क्या जिन यूज़र्स ने बचपन में कोडिंग शुरू की, उनकी compensation वयस्क उम्र में शुरू करने वालों से अधिक है?
Python में Hypothesis Testing

परिकल्पनाएँ

$H_{0}$: जिन लोगों ने पहले बचपन में कोड किया और जिन लोगों ने पहले वयस्क के रूप में कोड किया, उनकी औसत compensation (USD में) समान है.

$H_{0}$: $\mu_{child} = \mu_{adult}$

$H_{0}$: $\mu_{child} - \mu_{adult} = 0$

$H_{A}$: जिन लोगों ने पहले बचपन में कोड किया, उनकी औसत compensation (USD में) अधिक है बनिस्बत उन लोगों के जिन्होंने पहले वयस्क के रूप में कोड किया.

$H_{A}$: $\mu_{child} > \mu_{adult}$

$H_{A}$: $\mu_{child} - \mu_{adult} > 0$

Python में Hypothesis Testing

समूह-वार सारांश आँकड़े निकालना

stack_overflow.groupby('age_first_code_cut')['converted_comp'].mean()
age_first_code_cut
adult    111313.311047
child    132419.570621
Name: converted_comp, dtype: float64
Python में Hypothesis Testing

टेस्ट स्टैटिस्टिक्स

  • सैंपल mean, population mean का अनुमान लगाता है
  • $\bar{x}$ - सैंपल mean
  • $\bar{x}_{child}$ - बचपन में पहले कोड करने वालों की सैंपल mean compensation
  • $\bar{x}_{adult}$ - वयस्क के रूप में पहले कोड करने वालों की सैंपल mean compensation
  • $\bar{x}_{child} - \bar{x}_{adult}$ - एक टेस्ट स्टैटिस्टिक
  • z-score - एक (standardized) टेस्ट स्टैटिस्टिक
Python में Hypothesis Testing

टेस्ट स्टैटिस्टिक को मानकीकृत करना

$z = \dfrac{\text{sample stat} - \text{population parameter}}{\text{standard error}}$

$t = \dfrac{\text{difference in sample stats} - \text{difference in population parameters}}{\text{standard error}}$

$t = \dfrac{(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}}) - (\mu_{\text{child}} - \mu_{\text{adult}})}{SE(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}})}$

Python में Hypothesis Testing

स्टैंडर्ड एरर

$SE(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}}) \approx \sqrt{\dfrac{s_{\text{child}}^2}{n_{\text{child}}} + \dfrac{s_{\text{adult}}^2}{n_{\text{adult}}}}$

$s$ वैरिएबल का standard deviation है

$n$ सैंपल आकार है (सैंपल में observations/rows की संख्या)

Python में Hypothesis Testing

मान लें शून्य परिकल्पना सही है

$t = \dfrac{(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}}) - (\mu_{\text{child}} - \mu_{\text{adult}})}{SE(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}})}$

$H_{0}$: $\mu_{\text{child}} - \mu_{\text{adult}} = 0$    $\rightarrow$     $t = \dfrac{(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}}) }{SE(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}})}$

$t = \dfrac{(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}})}{\sqrt{\dfrac{s_{\text{child}}^2}{n_{\text{child}}} + \dfrac{s_{\text{adult}}^2}{n_{\text{adult}}}}}$

Python में Hypothesis Testing

शून्य परिकल्पना मानकर गणनाएँ

xbar = stack_overflow.groupby('age_first_code_cut')['converted_comp'].mean()
adult    111313.311047
child    132419.570621
Name: converted_comp, dtype: float64 age_first_code_cut
s = stack_overflow.groupby('age_first_code_cut')['converted_comp'].std()
adult    271546.521729
child    255585.240115
Name: converted_comp, dtype: float64 age_first_code_cut
n = stack_overflow.groupby('age_first_code_cut')['converted_comp'].count()
adult    1376
child     885
Name: converted_comp, dtype: int64
Python में Hypothesis Testing

टेस्ट स्टैटिस्टिक की गणना

$t = \dfrac{(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}})}{\sqrt{\dfrac{s_{\text{child}}^2}{n_{\text{child}}} + \dfrac{s_{\text{adult}}^2}{n_{\text{adult}}}}}$

import numpy as np
numerator = xbar_child - xbar_adult
denominator = np.sqrt(s_child ** 2 / n_child + s_adult ** 2 / n_adult)
t_stat = numerator / denominator
1.8699313316221844
Python में Hypothesis Testing

अभ्यास करते हैं!

Python में Hypothesis Testing

Preparing Video For Download...