Aliou12 commited on
Commit
adf12c1
·
1 Parent(s): e7123e5

new mise a jours

Browse files
Files changed (2) hide show
  1. app.py +108 -0
  2. requirement.txt +8 -0
app.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import seaborn as sns
5
+ import matplotlib.pyplot as plt
6
+ import scipy.stats as stats
7
+ import statsmodels.api as sm
8
+ import statsmodels.formula.api as smf
9
+ from sklearn.cluster import KMeans
10
+ from statsmodels.stats.multicomp import pairwise_tukeyhsd
11
+
12
+ # 🏠 Titre de l'application
13
+ st.title("📊 Analyse des Évaluations des Clients avec ANOVA")
14
+
15
+ # 📂 Upload du fichier
16
+ uploaded_file = st.file_uploader("📂 Téléchargez le fichier 'supermarket_sales.csv'", type=["csv"])
17
+
18
+ if uploaded_file is not None:
19
+ # 📖 Charger les données
20
+ data = pd.read_csv(uploaded_file)
21
+
22
+ # ✅ Renommer les colonnes pour éviter les erreurs de syntaxe
23
+ data = data.rename(columns={'Product line': 'Product_line'})
24
+
25
+ # ✅ Sélectionner les colonnes nécessaires
26
+ data = data[['Product_line', 'Payment', 'Rating']]
27
+ data.dropna(inplace=True) # Supprimer les valeurs manquantes
28
+
29
+ # ✅ Convertir en catégories
30
+ data['Product_line'] = data['Product_line'].astype('category')
31
+ data['Payment'] = data['Payment'].astype('category')
32
+
33
+ # 📌 Afficher un aperçu des données
34
+ st.subheader("📊 Aperçu des Données")
35
+ st.write(data.head())
36
+
37
+ # ============================
38
+ # 📌 Vérification des Hypothèses
39
+ # ============================
40
+
41
+ st.subheader("🧪 Vérification des Hypothèses")
42
+
43
+ # 🔹 Test de normalité des résidus (Shapiro-Wilk)
44
+ model = smf.ols('Rating ~ C(Product_line) * C(Payment)', data=data).fit()
45
+ residuals = model.resid
46
+ shapiro_test = stats.shapiro(residuals)
47
+ st.write(f"✅ Test de Shapiro-Wilk (Normalité) : **p-value = {shapiro_test.pvalue:.4f}**")
48
+
49
+ # 🔹 Test d'homogénéité des variances (Levene)
50
+ group_list = [data['Rating'][data['Product_line'] == cat] for cat in data['Product_line'].unique()]
51
+ levene_test = stats.levene(*group_list)
52
+ st.write(f"✅ Test de Levene (Homogénéité des variances) : **p-value = {levene_test.pvalue:.4f}**")
53
+
54
+ # ============================
55
+ # 📌 ANOVA à Deux Facteurs
56
+ # ============================
57
+
58
+ st.subheader("📊 ANOVA à Deux Facteurs")
59
+ anova_table = sm.stats.anova_lm(model, typ=2)
60
+ st.write(anova_table)
61
+
62
+ # ============================
63
+ # 📌 Comparaisons Post-Hoc (Tukey HSD)
64
+ # ============================
65
+
66
+ st.subheader("📌 Comparaisons Post-Hoc (Tukey HSD)")
67
+ tukey = pairwise_tukeyhsd(data['Rating'], data['Product_line'])
68
+ st.write(tukey.summary())
69
+
70
+ # ============================
71
+ # 📊 Visualisation des Résultats
72
+ # ============================
73
+
74
+ st.subheader("📊 Visualisation des Résultats")
75
+
76
+ # 🔹 Boxplot
77
+ fig, ax = plt.subplots(figsize=(10, 5))
78
+ sns.boxplot(x='Product_line', y='Rating', hue='Payment', data=data, ax=ax)
79
+ plt.xticks(rotation=45)
80
+ st.pyplot(fig)
81
+
82
+ # 🔹 Heatmap des Moyennes des Évaluations
83
+ mean_ratings = data.groupby(['Product_line', 'Payment'])['Rating'].mean().unstack()
84
+ fig, ax = plt.subplots(figsize=(8, 5))
85
+ sns.heatmap(mean_ratings, annot=True, cmap='coolwarm', ax=ax)
86
+ st.pyplot(fig)
87
+
88
+ # ============================
89
+ # 📌 Régression Linéaire Multiple
90
+ # ============================
91
+
92
+ st.subheader("📈 Régression Linéaire Multiple")
93
+ lm_model = smf.ols('Rating ~ C(Product_line) + C(Payment)', data=data).fit()
94
+ st.write(lm_model.summary())
95
+
96
+ # ============================
97
+ # 📌 Clustering des Clients (K-Means)
98
+ # ============================
99
+
100
+ st.subheader("🎯 Clustering des Clients (K-Means)")
101
+ kmeans = KMeans(n_clusters=3, random_state=42, n_init=10)
102
+ data['Cluster'] = kmeans.fit_predict(data[['Rating']])
103
+
104
+ # 🔹 Visualisation du Clustering
105
+ fig, ax = plt.subplots(figsize=(8, 5))
106
+ sns.scatterplot(x='Product_line', y='Rating', hue=data['Cluster'].astype(str), palette='viridis', data=data, ax=ax)
107
+ plt.xticks(rotation=45)
108
+ st.pyplot(fig)
requirement.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ numpy
4
+ seaborn
5
+ matplotlib
6
+ scipy
7
+ statsmodels
8
+ scikit-learn