Spaces:
Runtime error
Runtime error
File size: 4,384 Bytes
aa26248 8868a0a aa26248 c5354fe 99d91ca c5354fe 935a4f9 c5354fe 935a4f9 c5354fe 935a4f9 c5354fe 935a4f9 c5354fe 935a4f9 c5354fe 935a4f9 386b94c c5354fe 935a4f9 c5354fe 935a4f9 c5354fe 0d4423b c5354fe 781986d aa26248 36d3d07 aa26248 |
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 |
import gradio as gr
import pandas as pd
from sklearn import datasets
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.preprocessing import LabelEncoder
def findCorrelation(dataset, target):
df = pd.read_csv(dataset.name)
non_numeric_cols = df.select_dtypes('object').columns.tolist()
if target in non_numeric_cols:
label_encoder = LabelEncoder()
df[non_numeric_col] = label_encoder.fit_transform(df[target])
d = df.corr()[target].to_dict()
d.pop(target)
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")
try:
fig2 = plt.figure()
sns.regplot(x=df[keys[0][0]], y=df[target])
except:
fig2 = plt.figure()
try:
fig3 = plt.figure()
sns.regplot(x=df[keys[1][0]], y=df[target])
except:
fig3 = plt.figure()
try:
fig4 = plt.figure()
sns.regplot(x=df[keys[2][0]], y=df[target])
except:
fig4 = plt.figure()
return d, fig1, fig2, fig3, fig4
css = """
footer {display:none !important}
.output-markdown{display:none !important}
div[data-testid="label"] {height: 18rem !important; overflow-x : hidden !important; overflow-y: scroll !important;}
.max-h-\[30rem\] {max-height: 18rem !important;}
.gr-button-lg {
z-index: 14;
width: 113px;
height: 30px;
left: 0px;
top: 0px;
padding: 0px;
cursor: pointer !important;
background: none rgb(17, 20, 45) !important;
border: none !important;
text-align: center !important;
font-size: 14px !important;
font-weight: 500 !important;
color: rgb(255, 255, 255) !important;
line-height: 1 !important;
border-radius: 6px !important;
transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;
box-shadow: none !important;
}
.gr-button-lg:hover{
z-index: 14;
width: 113px;
height: 30px;
left: 0px;
top: 0px;
padding: 0px;
cursor: pointer !important;
background: none rgb(66, 133, 244) !important;
border: none !important;
text-align: center !important;
font-size: 14px !important;
font-weight: 500 !important;
color: rgb(255, 255, 255) !important;
line-height: 1 !important;
border-radius: 6px !important;
transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;
box-shadow: rgb(0 0 0 / 23%) 0px 1px 7px 0px !important;
}
.hover\:bg-orange-50:hover {
--tw-bg-opacity: 1 !important;
background-color: rgb(229,225,255) !important;
}
.to-orange-200 {
--tw-gradient-to: rgb(37 56 133 / 37%) !important;
}
.from-orange-400 {
--tw-gradient-from: rgb(17, 20, 45) !important;
--tw-gradient-to: rgb(255 150 51 / 0);
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to) !important;
}
.group-hover\:from-orange-500{
--tw-gradient-from:rgb(17, 20, 45) !important;
--tw-gradient-to: rgb(37 56 133 / 37%);
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to) !important;
}
.group:hover .group-hover\:text-orange-500{
--tw-text-opacity: 1 !important;
color:rgb(37 56 133 / var(--tw-text-opacity)) !important;
}
"""
with gr.Blocks(title="Find Correlation | Data Science Dojo", css = css) as demo:
with gr.Row():
with gr.Column():
file = gr.File()
with gr.Column():
inp = gr.Textbox(placeholder="Enter the target feature name", label="Target Variable")
btn = gr.Button("Find correlation")
gr.Markdown(
"""
## Correlation with other numeric features
""")
with gr.Row():
labels = gr.Label(num_top_classes = 10)
gr.Markdown(
"""
## HeatMap
""")
with gr.Row():
fig1 = gr.Plot()
gr.Markdown(
"""
## Plot of top 3 correlated features
""")
with gr.Row():
with gr.Column():
fig2 = gr.Plot()
with gr.Column():
fig3 = gr.Plot()
with gr.Row():
fig4 = gr.Plot()
with gr.Row():
gr.Examples(
examples = [["boston.csv", "MEDV"]], fn=findCorrelation, inputs=[file, inp], outputs=[labels, fig1, fig2, fig3, fig4], cache_examples=True)
btn.click( fn=findCorrelation, inputs=[file, inp], outputs=[labels, fig1, fig2, fig3, fig4])
demo.launch() |