Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
|
|
2 |
import numpy as np
|
3 |
import pandas as pd
|
4 |
from sklearn.cluster import KMeans, AgglomerativeClustering, DBSCAN, Birch, MeanShift
|
5 |
-
from sklearn_extra.cluster import KMedoids
|
6 |
from sklearn.mixture import GaussianMixture
|
7 |
from sklearn.decomposition import PCA
|
8 |
from scipy.cluster.hierarchy import linkage, dendrogram
|
@@ -23,9 +22,6 @@ def apply_clustering(algorithm, n_clusters, dataset):
|
|
23 |
if algorithm == "KMeans":
|
24 |
model = KMeans(n_clusters=n_clusters, random_state=42)
|
25 |
labels = model.fit_predict(data_matrix)
|
26 |
-
elif algorithm == "KMedoid (PAM)":
|
27 |
-
model = KMedoids(n_clusters=n_clusters, method='pam', random_state=42)
|
28 |
-
labels = model.fit_predict(data_matrix)
|
29 |
elif algorithm == "Fuzzy C-Means (FCM)":
|
30 |
# Use skfuzzy for Fuzzy C-Means
|
31 |
cntr, u, _, _, _, _, _ = fuzz.cmeans(data_matrix.T, n_clusters, 2, error=0.005, maxiter=1000)
|
@@ -84,7 +80,6 @@ def main_interface():
|
|
84 |
algorithm = gr.Dropdown(
|
85 |
choices=[
|
86 |
"KMeans",
|
87 |
-
"KMedoid (PAM)",
|
88 |
"Fuzzy C-Means (FCM)",
|
89 |
"Agglomerative Hierarchical Clustering (AHC)",
|
90 |
"BIRCH",
|
@@ -104,8 +99,11 @@ def main_interface():
|
|
104 |
fn=apply_clustering,
|
105 |
inputs=[algorithm, n_clusters, dataset],
|
106 |
outputs=[output_text, output_image]
|
107 |
-
).launch(
|
108 |
|
109 |
# Run the application
|
110 |
if __name__ == "__main__":
|
111 |
main_interface()
|
|
|
|
|
|
|
|
2 |
import numpy as np
|
3 |
import pandas as pd
|
4 |
from sklearn.cluster import KMeans, AgglomerativeClustering, DBSCAN, Birch, MeanShift
|
|
|
5 |
from sklearn.mixture import GaussianMixture
|
6 |
from sklearn.decomposition import PCA
|
7 |
from scipy.cluster.hierarchy import linkage, dendrogram
|
|
|
22 |
if algorithm == "KMeans":
|
23 |
model = KMeans(n_clusters=n_clusters, random_state=42)
|
24 |
labels = model.fit_predict(data_matrix)
|
|
|
|
|
|
|
25 |
elif algorithm == "Fuzzy C-Means (FCM)":
|
26 |
# Use skfuzzy for Fuzzy C-Means
|
27 |
cntr, u, _, _, _, _, _ = fuzz.cmeans(data_matrix.T, n_clusters, 2, error=0.005, maxiter=1000)
|
|
|
80 |
algorithm = gr.Dropdown(
|
81 |
choices=[
|
82 |
"KMeans",
|
|
|
83 |
"Fuzzy C-Means (FCM)",
|
84 |
"Agglomerative Hierarchical Clustering (AHC)",
|
85 |
"BIRCH",
|
|
|
99 |
fn=apply_clustering,
|
100 |
inputs=[algorithm, n_clusters, dataset],
|
101 |
outputs=[output_text, output_image]
|
102 |
+
).launch()
|
103 |
|
104 |
# Run the application
|
105 |
if __name__ == "__main__":
|
106 |
main_interface()
|
107 |
+
|
108 |
+
|
109 |
+
|