Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,54 +3,37 @@ import pandas as pd
|
|
3 |
from sklearn import datasets
|
4 |
import seaborn as sns
|
5 |
import matplotlib.pyplot as plt
|
|
|
6 |
|
7 |
def findCorrelation(dataset, target):
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
print("\n")
|
11 |
-
|
12 |
-
print(target)
|
13 |
-
print(type(target))
|
14 |
-
print(str(target))
|
15 |
-
print("\n")
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
|
21 |
d = df.corr()[target].to_dict()
|
22 |
d.pop(target)
|
23 |
-
print(d)
|
24 |
-
keys = sorted(d.items(), key=lambda x: x[0], reverse=True)
|
25 |
-
|
26 |
-
print(keys)
|
27 |
-
print(type(keys))
|
28 |
|
|
|
|
|
29 |
fig1 = plt.figure()
|
30 |
hm = sns.heatmap(df.corr(), annot = True)
|
31 |
hm.set(title = "Correlation matrix of dataset\n")
|
32 |
-
|
33 |
-
print("\n Fig 1")
|
34 |
|
35 |
fig2 = plt.figure()
|
36 |
-
# use the function regplot to make a scatterplot
|
37 |
-
print(keys[0])
|
38 |
sns.regplot(x=df[keys[0][0]], y=df[target])
|
39 |
-
print("\n Fig 2")
|
40 |
|
41 |
fig3 = plt.figure()
|
42 |
-
# use the function regplot to make a scatterplot
|
43 |
sns.regplot(x=df[keys[1][0]], y=df[target])
|
44 |
|
45 |
-
print("\n Fig 3")
|
46 |
-
|
47 |
fig4 = plt.figure()
|
48 |
-
# use the function regplot to make a scatterplot
|
49 |
sns.regplot(x=df[keys[2][0]], y=df[target])
|
50 |
-
|
51 |
-
print("\n Fig 4")
|
52 |
|
53 |
return d, fig1, fig2, fig3, fig4
|
54 |
|
55 |
-
demo = gr.Interface(fn=findCorrelation, inputs=[gr.File(), 'text'], outputs=[gr.Label(num_top_classes =
|
56 |
demo.launch(debug=True)
|
|
|
3 |
from sklearn import datasets
|
4 |
import seaborn as sns
|
5 |
import matplotlib.pyplot as plt
|
6 |
+
from sklearn.preprocessing import LabelEncoder
|
7 |
|
8 |
def findCorrelation(dataset, target):
|
9 |
+
|
10 |
+
df = pd.read_csv(dataset.name)
|
11 |
|
12 |
+
non_numeric_cols = df.select_dtypes('object').columns.tolist()
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
for non_numeric_col in non_numeric_cols:
|
15 |
+
label_encoder = LabelEncoder()
|
16 |
+
df[non_numeric_col] = label_encoder.fit_transform(df[non_numeric_col])
|
17 |
|
18 |
d = df.corr()[target].to_dict()
|
19 |
d.pop(target)
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
keys = sorted(d.items(), key=lambda x: x[0], reverse=True)
|
22 |
+
|
23 |
fig1 = plt.figure()
|
24 |
hm = sns.heatmap(df.corr(), annot = True)
|
25 |
hm.set(title = "Correlation matrix of dataset\n")
|
|
|
|
|
26 |
|
27 |
fig2 = plt.figure()
|
|
|
|
|
28 |
sns.regplot(x=df[keys[0][0]], y=df[target])
|
|
|
29 |
|
30 |
fig3 = plt.figure()
|
|
|
31 |
sns.regplot(x=df[keys[1][0]], y=df[target])
|
32 |
|
|
|
|
|
33 |
fig4 = plt.figure()
|
|
|
34 |
sns.regplot(x=df[keys[2][0]], y=df[target])
|
|
|
|
|
35 |
|
36 |
return d, fig1, fig2, fig3, fig4
|
37 |
|
38 |
+
demo = gr.Interface(fn=findCorrelation, inputs=[gr.File(), 'text'], outputs=[gr.Label(num_top_classes = 6), gr.Plot(), gr.Plot(), gr.Plot(), gr.Plot()], title="Find correlation")
|
39 |
demo.launch(debug=True)
|