Sakil commited on
Commit
770a7f9
·
1 Parent(s): ae29f3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -3
app.py CHANGED
@@ -1,10 +1,45 @@
1
  import gradio as gr
2
  import pandas as pd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  def predict(file_obj):
5
- df = pd.read_csv(file_obj)
6
- return df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
 
9
- iface = gr.Interface(predict,inputs="file",outputs="dataframe",title='Cramer V Test',description="Cramer Test")
10
  iface.launch(inline=False)
 
1
  import gradio as gr
2
  import pandas as pd
3
+ import numpy as np
4
+ import pandas as pd
5
+ import scipy.stats as ss
6
+ import seaborn as sns
7
+ from scipy.stats import chi2_contingency
8
+ import numpy as np
9
+ import seaborn as sns
10
+ import matplotlib.pyplot as plt
11
+ rows= []
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
15
+ obs = np.sum(crosstab) # Number of observations
16
+ mini = min(crosstab.shape)-1 # Take the minimum value between the columns and the rows of the cross table
17
+ return (stat/(obs*mini))
18
 
19
  def predict(file_obj):
20
+ df = pd.read_csv(file_obj.name,dtype=str)
21
+ cat_df = df.select_dtypes(include=['object']).copy()
22
+ for var1 in cat_df:
23
+ col = []
24
+ for var2 in cat_df :
25
+ cramers =cramers_V(cat_df[var1], cat_df[var2]) # Cramer's V test
26
+ col.append(round(cramers,2)) # Keeping of the rounded value of the Cramer's V
27
+ rows.append(col)
28
+ cramers_results = np.array(rows)
29
+ df_final= pd.DataFrame(cramers_results, columns = cat_df.columns, index =cat_df.columns)
30
+ # return df_final
31
+ data = np.random.randint(low=1,
32
+ high=1000,
33
+ size=(10, 10))
34
+ annot = True
35
+
36
+ # plotting the heatmap
37
+ hm = sns.heatmap(data=df_final,
38
+ annot=annot)
39
+ # plt.show()
40
+ # plt.figure()
41
+ return plt.gcf()
42
 
43
 
44
+ iface = gr.Interface(predict,inputs="file",outputs="plot",title='Correlation Tool for Categorical features',description="This tool identifies and explains the correlation between categorical features.")
45
  iface.launch(inline=False)