# 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 binomtest ``` # 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> # Binomtest ```python p = 0.8 ``` ```python df["time"].value_counts(normalize=True) ``` time Dinner 0.721311 Lunch 0.278689 Name: proportion, dtype: float64 ```python k = df["time"].value_counts()["Dinner"] k ``` 176 ```python n = len(df) n ``` 244 ```python binomtest(k=k, n=n, p=p) ``` BinomTestResult(k=176, n=244, alternative='two-sided', statistic=0.7213114754098361, pvalue=0.002988997747005771) # En résumé: ```python p = 0.8 print(f"H0: \"{p*100} % des pourboires sont donnés le soir\"") print() alpha = 0.02 p_value = binomtest(k=k, n=n, p=p).pvalue 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: "80.0 % des pourboires sont donnés le soir" Nous avons suffisamment d'évidences pour rejeter H0