FahadAlam's picture
Update app.py
126b501
raw
history blame
1.22 kB
import gradio as gr
import pandas as pd
from sklearn import datasets
import seaborn as sns
import matplotlib.pyplot as plt
def findCorrelation(dataset, target):
print(dataset.name)
print("\n")
print(target)
print(type(target))
print(str(target))
print("\n")
df = pd.read_csv(dataset.name)
print(df)
print("\n")
d = df.corr()[target].to_dict()
d.pop(target)
print(d)
keys = sorted(d.items(), key=lambda x: x[0], reverse=True)
fig1 = plt.figure()
hm = sns.heatmap(df.corr(), annot = True)
hm.set(title = "Correlation matrix of dataset\n")
fig2 = plt.figure()
# use the function regplot to make a scatterplot
sns.regplot(x=df[keys[0]], y=df[target])
fig3 = plt.figure()
# use the function regplot to make a scatterplot
sns.regplot(x=df[keys[1]], y=df[target])
fig4 = plt.figure()
# use the function regplot to make a scatterplot
sns.regplot(x=df[keys[2]], y=df[target])
labels = {key: d[key] for key in keys[10]}
return labels, fig1, fig2, fig3, fig4
demo = gr.Interface(fn=findCorrelation, inputs=[gr.File(), 'text'], outputs=[gr.Label(), gr.Plot(), gr.Plot(), gr.Plot(), gr.Plot()], title="Find correlation")
demo.launch(debug=True)