Spaces:
Sleeping
Sleeping
Commit
·
8b6c8b4
1
Parent(s):
85cd8b9
T-nse Test
Browse files
app.py
CHANGED
|
@@ -753,56 +753,56 @@ def run_model(model_name):
|
|
| 753 |
reset_button = Button(label="Reset Colors", button_type="primary")
|
| 754 |
line_source = ColumnDataSource(data={'x': [], 'y': []})
|
| 755 |
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
|
| 803 |
-
|
| 804 |
|
| 805 |
-
|
| 806 |
|
| 807 |
buffer = io.BytesIO()
|
| 808 |
df_table.to_excel(buffer, index=False)
|
|
@@ -816,7 +816,7 @@ def run_model(model_name):
|
|
| 816 |
key=f"download_button_excel_{model_name}"
|
| 817 |
)
|
| 818 |
|
| 819 |
-
if reduction_method == "PCA"
|
| 820 |
st.markdown("## PCA - Solo Muestras Reales")
|
| 821 |
# -------------------------------------------------------------------------
|
| 822 |
# 1. PCA sobre las muestras reales
|
|
|
|
| 753 |
reset_button = Button(label="Reset Colors", button_type="primary")
|
| 754 |
line_source = ColumnDataSource(data={'x': [], 'y': []})
|
| 755 |
|
| 756 |
+
if (reduction_method == "t-SNE" and N_COMPONENTS == 2) or (reduction_method == "PCA" and N_COMPONENTS == 2):
|
| 757 |
+
fig, real_renderers, synthetic_renderers, pretrained_renderers = create_figure(
|
| 758 |
+
result["dfs_reduced"],
|
| 759 |
+
result["unique_subsets"],
|
| 760 |
+
get_color_maps(result["unique_subsets"]),
|
| 761 |
+
model_name
|
| 762 |
+
)
|
| 763 |
+
fig.line('x', 'y', source=line_source, line_width=2, line_color='black')
|
| 764 |
+
centers_real = calculate_cluster_centers(result["dfs_reduced"]["real"], result["unique_subsets"]["real"])
|
| 765 |
+
real_centers_js = {k: [v[0], v[1]] for k, v in centers_real.items()}
|
| 766 |
+
synthetic_centers = {}
|
| 767 |
+
synth_labels = sorted(result["dfs_reduced"]["synthetic"]['label'].unique().tolist())
|
| 768 |
+
for label in synth_labels:
|
| 769 |
+
subset = result["dfs_reduced"]["synthetic"][result["dfs_reduced"]["synthetic"]['label'] == label]
|
| 770 |
+
if 'x' in subset.columns and 'y' in subset.columns:
|
| 771 |
+
synthetic_centers[label] = [subset['x'].mean(), subset['y'].mean()]
|
| 772 |
+
callback = CustomJS(args=dict(source=source_table, line_source=line_source,
|
| 773 |
+
synthetic_centers=synthetic_centers,
|
| 774 |
+
real_centers=real_centers_js,
|
| 775 |
+
real_select=real_select),
|
| 776 |
+
code="""
|
| 777 |
+
var selected = source.selected.indices;
|
| 778 |
+
if (selected.length > 0) {
|
| 779 |
+
var idx = selected[0];
|
| 780 |
+
var data = source.data;
|
| 781 |
+
var synth_label = data['Synthetic'][idx];
|
| 782 |
+
var real_label = real_select.value;
|
| 783 |
+
var syn_coords = synthetic_centers[synth_label];
|
| 784 |
+
var real_coords = real_centers[real_label];
|
| 785 |
+
line_source.data = {'x': [syn_coords[0], real_coords[0]], 'y': [syn_coords[1], real_coords[1]]};
|
| 786 |
+
line_source.change.emit();
|
| 787 |
+
} else {
|
| 788 |
+
line_source.data = {'x': [], 'y': []};
|
| 789 |
+
line_source.change.emit();
|
| 790 |
+
}
|
| 791 |
+
""")
|
| 792 |
+
source_table.selected.js_on_change('indices', callback)
|
| 793 |
+
real_select.js_on_change('value', callback)
|
| 794 |
|
| 795 |
+
reset_callback = CustomJS(args=dict(line_source=line_source),
|
| 796 |
+
code="""
|
| 797 |
+
line_source.data = {'x': [], 'y': []};
|
| 798 |
+
line_source.change.emit();
|
| 799 |
+
""")
|
| 800 |
+
reset_button.js_on_event("button_click", reset_callback)
|
| 801 |
+
layout = column(fig, result["scatter_fig"], column(real_select, reset_button, data_table))
|
| 802 |
+
else:
|
| 803 |
+
layout = column(result["scatter_fig"], column(real_select, reset_button, data_table))
|
| 804 |
|
| 805 |
+
st.bokeh_chart(layout, use_container_width=True)
|
| 806 |
|
| 807 |
buffer = io.BytesIO()
|
| 808 |
df_table.to_excel(buffer, index=False)
|
|
|
|
| 816 |
key=f"download_button_excel_{model_name}"
|
| 817 |
)
|
| 818 |
|
| 819 |
+
if reduction_method == "PCA":
|
| 820 |
st.markdown("## PCA - Solo Muestras Reales")
|
| 821 |
# -------------------------------------------------------------------------
|
| 822 |
# 1. PCA sobre las muestras reales
|