Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ from scipy.stats import chi2_contingency
|
|
8 |
import numpy as np
|
9 |
import seaborn as sns
|
10 |
import matplotlib.pyplot as plt
|
11 |
-
|
12 |
def cramers_V(var1,var2) :
|
13 |
crosstab =np.array(pd.crosstab(var1,var2, rownames=None, colnames=None)) # Cross table building
|
14 |
stat = chi2_contingency(crosstab)[0] # Keeping of the test statistic of the Chi2 test
|
@@ -17,6 +17,7 @@ def cramers_V(var1,var2) :
|
|
17 |
return (stat/(obs*mini))
|
18 |
|
19 |
def predict(file_obj):
|
|
|
20 |
df = pd.read_csv(file_obj.name)
|
21 |
cat_df = df.select_dtypes(include=['object'])
|
22 |
rows= []
|
@@ -28,20 +29,27 @@ def predict(file_obj):
|
|
28 |
rows.append(col)
|
29 |
cramers_results = np.array(rows)
|
30 |
df_final= pd.DataFrame(cramers_results, columns = cat_df.columns, index =cat_df.columns)
|
31 |
-
|
32 |
# return df_final
|
33 |
-
data = np.random.randint(low=1,
|
34 |
-
|
35 |
-
|
36 |
annot = True
|
37 |
|
38 |
# plotting the heatmap
|
|
|
39 |
hm = sns.heatmap(data=df_final,
|
40 |
annot=annot)
|
41 |
-
# plt.show()
|
42 |
-
# plt.figure()
|
|
|
|
|
43 |
return plt.gcf()
|
|
|
|
|
|
|
|
|
44 |
|
45 |
|
46 |
-
iface = gr.Interface(predict,inputs="file",outputs="plot",theme="dark-peach",
|
47 |
iface.launch(inline=False)
|
|
|
8 |
import numpy as np
|
9 |
import seaborn as sns
|
10 |
import matplotlib.pyplot as plt
|
11 |
+
import os
|
12 |
def cramers_V(var1,var2) :
|
13 |
crosstab =np.array(pd.crosstab(var1,var2, rownames=None, colnames=None)) # Cross table building
|
14 |
stat = chi2_contingency(crosstab)[0] # Keeping of the test statistic of the Chi2 test
|
|
|
17 |
return (stat/(obs*mini))
|
18 |
|
19 |
def predict(file_obj):
|
20 |
+
|
21 |
df = pd.read_csv(file_obj.name)
|
22 |
cat_df = df.select_dtypes(include=['object'])
|
23 |
rows= []
|
|
|
29 |
rows.append(col)
|
30 |
cramers_results = np.array(rows)
|
31 |
df_final= pd.DataFrame(cramers_results, columns = cat_df.columns, index =cat_df.columns)
|
32 |
+
|
33 |
# return df_final
|
34 |
+
# data = np.random.randint(low=1,
|
35 |
+
# high=1000,
|
36 |
+
# size=(10, 10))
|
37 |
annot = True
|
38 |
|
39 |
# plotting the heatmap
|
40 |
+
plt.close('all')
|
41 |
hm = sns.heatmap(data=df_final,
|
42 |
annot=annot)
|
43 |
+
# return plt.show()
|
44 |
+
# return plt.figure()
|
45 |
+
plt.savefig('box.png')
|
46 |
+
|
47 |
return plt.gcf()
|
48 |
+
# plt.clf()
|
49 |
+
# return plt.plot()
|
50 |
+
|
51 |
+
|
52 |
|
53 |
|
54 |
+
iface = gr.Interface(predict,inputs="file",outputs="plot",theme="dark-peach",title='Correlation Tool for Categorical features',description="This tool identifies and explains the correlation between categorical features.")
|
55 |
iface.launch(inline=False)
|