-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDescriptive_Analysis.py
More file actions
252 lines (169 loc) · 7.53 KB
/
Descriptive_Analysis.py
File metadata and controls
252 lines (169 loc) · 7.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import streamlit as st
import pandas as pd
import numpy as np
import scipy.stats as stats
from sklearn.linear_model import LinearRegression
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from PIL import Image
def run_descriptive_analysis():
hide_menu = """
<style>
#MainMenu {
visibility: hidden;
}
footer {
visibility: visible;
text-align: center;
}
footer:after {
content: "Copyright © 2023 Curated with ❤️ by Surya";
display: block;
position: relative;
color: DarkGrey;
margin: auto;
}
<style>
"""
@st.cache
def load_image(image_file):
img = Image.open(image_file)
return img
info = Image.open("Images/descriptive.png")
'''st.set_page_config(
page_title="Descriptive Analysis",
page_icon=info,
#layout="wide",
)'''
st.markdown(hide_menu, unsafe_allow_html=True)
def run_descriptive_analysis():
def basic_analysis(data):
basic_expander = st.expander("🔍 Basic Analysis")
with basic_expander:
st.header("Basic Analysis 🔍")
st.write("#### 🔢 Count")
st.write(data.shape[0])
st.markdown("""---""")
st.write("#### 🔢 Mean", data.mean())
st.markdown("""---""")
st.write("#### 🔢 Standard Deviation", data.std())
st.markdown("""---""")
st.write("#### 🔢 Minimum", data.min())
st.markdown("""---""")
st.write("#### 🔢 25th Percentile (Q1)", data.quantile(0.25))
st.markdown("""---""")
st.write("#### 🔢 50th Percentile (Median)", data.median())
st.markdown("""---""")
st.write("#### 🔢 75th Percentile (Q3)", data.quantile(0.75))
st.markdown("""---""")
st.write("#### 🔢 Maximum", data.max())
def kde_estimation(data):
selected_variable = st.selectbox("Select a Variable", data.columns)
fig, ax = plt.subplots()
sns.kdeplot(data[selected_variable], shade=True, ax=ax)
ax.set_xlabel(selected_variable)
ax.set_ylabel("Density")
st.pyplot(fig)
def multivariate_analysis(data):
st.write("Select variables for multivariate analysis:")
selected_variables = st.multiselect("Select Variables", data.columns)
sns.pairplot(data[selected_variables], diag_kind='kde')
st.pyplot()
def intermediate_analysis(data):
intermediate_expander = st.expander("📈 Intermediate Analysis")
with intermediate_expander:
st.header("Intermediate Analysis 📈")
st.write("#### 🧮 Range", data.max() - data.min())
st.markdown("""---""")
st.write("#### 🧮 Variance", data.var())
st.markdown("""---""")
st.write("#### 🧮 Coefficient of Variation (CV)", data.std() / data.mean())
st.markdown("""---""")
st.write("#### 🧮 Skewness", stats.skew(data))
st.markdown("""---""")
st.write("#### 🧮 Kurtosis", stats.kurtosis(data))
st.markdown("""---""")
st.write("#### 🧮 Interquartile Range (IQR)", data.quantile(0.75) - data.quantile(0.25))
st.markdown("""---""")
st.write("#### 🧮 Median Absolute Deviation (MAD)", data.mad())
st.markdown("""---""")
st.write("#### 🧮 Median Absolute Deviation from the Median (MAD-Median)", stats.median_absolute_deviation(data))
st.markdown("""---""")
st.write("#### 🧮 Z-Score", np.abs(stats.zscore(data)))
st.markdown("""---""")
st.write("#### 🧮 Kernerl Density Analyis (KDE)")
kde_estimation(data)
st.markdown("""---""")
def regression_analysis(data):
st.write("Select independent variable column:")
independent_variable = st.selectbox("Independent Variable", data.columns)
dependent_variable = st.selectbox("Dependent Variable", data.columns)
X = data[[independent_variable]]
y = data[dependent_variable]
model = LinearRegression()
model.fit(X, y)
st.write("Regression Coefficients:")
st.write("**Intercept** ")
st.write(model.intercept_)
st.write("**Slope** ")
st.write(model.coef_[0])
def harmonic_mean(data):
if (data <= 0).any().any():
st.warning("⚠️ Harmonic mean is not defined for data with negative or zero values.")
else:
harmonic_mean_value = stats.hmean(data)
st.write("Harmonic Mean:", harmonic_mean_value)
def cluster_analysis(data):
st.write("Select the number of clusters:")
num_clusters = st.slider("Number of Clusters", min_value=2, max_value=10, value=3)
st.write("Select features for clustering:")
default_features = [data.columns[0]]
feature_columns = st.multiselect("Select Features", data.columns, default=default_features)
X = data[feature_columns]
kmeans = KMeans(n_clusters=num_clusters, random_state=0)
data['Cluster'] = kmeans.fit_predict(X)
st.write("**Cluster Centers**")
st.write(kmeans.cluster_centers_)
st.write("**Clustered Data**")
st.write(data)
def advanced_analysis(data):
advanced_expander = st.expander("🚀 Advanced Analysis")
with advanced_expander:
st.header("Advanced Analysis 🚀")
st.write("#### 🌟 Coefficient of Quartile Deviation (CQD)", (data.quantile(0.75) - data.quantile(0.25)) / (data.quantile(0.75) + data.quantile(0.25)))
st.markdown("""---""")
st.write("#### 🌟 Range Interquartile Ratio (RIR)", (data.max() - data.min()) / (data.quantile(0.75) - data.quantile(0.25)))
st.markdown("""---""")
st.write("#### 🌟 Relative Range", (data.max() - data.min()) / (data.max() + data.min()))
st.markdown("""---""")
st.write("#### 🌟 Variability Ratio (VR)", data.std() / data.mean())
st.markdown("""---""")
st.write("#### 🌟 Geometric Mean", stats.gmean(data))
st.markdown("""---""")
st.write("#### 🌟 Harmonic Mean")
harmonic_mean(data)
st.markdown("""---""")
st.write("#### 🌟 Regression Analysis")
regression_analysis(data.select_dtypes(include=[np.number]))
st.markdown("""---""")
st.write("#### 🌟 Cluster Analysis")
cluster_analysis(data)
def main():
st.title("📊 Descriptive Analysis on Dataset")
st.write("")
st.write("")
uploaded_file = st.file_uploader("📂 Upload a CSV file", type=["csv"])
if uploaded_file is not None:
data = pd.read_csv(uploaded_file)
st.dataframe(data.head())
st.success("✅ CSV file uploaded successfully")
st.write('')
if data.select_dtypes(include=[np.number]).empty:
st.warning("⚠️ The uploaded dataset does not contain numerical columns.")
else:
basic_analysis(data.select_dtypes(include=[np.number]))
intermediate_analysis(data.select_dtypes(include=[np.number]))
advanced_analysis(data.select_dtypes(include=[np.number]))
if __name__ == "__main__":
main()