# Librairies ```python import numpy as np import pandas as pd import matplotlib import matplotlib.pyplot as plt import seaborn as sns import scipy from scipy.stats import ttest_1samp ``` # Data ```python df = sns.load_dataset("tips") df.head() ``` <div> <style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style> <table border="1" class="dataframe"> <thead> <tr style="text-align: right;"> <th></th> <th>total_bill</th> <th>tip</th> <th>sex</th> <th>smoker</th> <th>day</th> <th>time</th> <th>size</th> </tr> </thead> <tbody> <tr> <th>0</th> <td>16.99</td> <td>1.01</td> <td>Female</td> <td>No</td> <td>Sun</td> <td>Dinner</td> <td>2</td> </tr> <tr> <th>1</th> <td>10.34</td> <td>1.66</td> <td>Male</td> <td>No</td> <td>Sun</td> <td>Dinner</td> <td>3</td> </tr> <tr> <th>2</th> <td>21.01</td> <td>3.50</td> <td>Male</td> <td>No</td> <td>Sun</td> <td>Dinner</td> <td>3</td> </tr> <tr> <th>3</th> <td>23.68</td> <td>3.31</td> <td>Male</td> <td>No</td> <td>Sun</td> <td>Dinner</td> <td>2</td> </tr> <tr> <th>4</th> <td>24.59</td> <td>3.61</td> <td>Female</td> <td>No</td> <td>Sun</td> <td>Dinner</td> <td>4</td> </tr> </tbody> </table> </div> # T-Test 1 sample H0 : "le pourboire moyen est de 3.5 €" ```python df["tip"].describe() ``` count 244.000000 mean 2.998279 std 1.383638 min 1.000000 25% 2.000000 50% 2.900000 75% 3.562500 max 10.000000 Name: tip, dtype: float64 ```python ttest_1samp(df["tip"], popmean=3.5) ``` TtestResult(statistic=-5.664152292840388, pvalue=4.1605377123077016e-08, df=243) # En résumé ```python print("H0 : \"le pourboire moyen est de 3.5 €") print() p_value = ttest_1samp(df["tip"], popmean=3.5).pvalue alpha = 0.02 if p_value<alpha: print("Nous avons suffisamment d'évidences pour rejeter H0") else: print("Nous n'avons pas suffisamment d'évidences pour rejeter H0") ``` H0 : "le pourboire moyen est de 3.5 € Nous avons suffisamment d'évidences pour rejeter H0