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
*.mo
|
| 15 |
+
*.pot
|
| 16 |
+
|
| 17 |
+
# Django stuff:
|
| 18 |
+
*.log
|
| 19 |
+
local_settings.py
|
| 20 |
+
db.sqlite3
|
| 21 |
+
db.sqlite3-journal
|
| 22 |
+
|
| 23 |
+
# Flask stuff:
|
| 24 |
+
instance/
|
| 25 |
+
.webassets-cache
|
| 26 |
+
|
| 27 |
+
# Scrapy stuff:
|
| 28 |
+
.scrapy
|
| 29 |
+
|
| 30 |
+
# Sphinx documentation
|
| 31 |
+
docs/_build/
|
| 32 |
+
|
| 33 |
+
# PyBuilder
|
| 34 |
+
.pybuilder/
|
| 35 |
+
target/
|
| 36 |
+
|
| 37 |
+
# Jupyter Notebook
|
| 38 |
+
.ipynb_checkpoints
|
| 39 |
+
|
| 40 |
+
# IPython
|
| 41 |
+
profile_default/
|
| 42 |
+
ipython_config.py
|
| 43 |
+
|
| 44 |
+
# pyenv
|
| 45 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 46 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 47 |
+
# .python-version
|
| 48 |
+
|
| 49 |
+
# pipenv
|
| 50 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 51 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 52 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 53 |
+
# install all needed dependencies.
|
| 54 |
+
#Pipfile.lock
|
| 55 |
+
|
| 56 |
+
# poetry
|
| 57 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 58 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 59 |
+
# commonly ignored for libraries.
|
| 60 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 61 |
+
#poetry.lock
|
| 62 |
+
|
| 63 |
+
# pdm
|
| 64 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 65 |
+
#pdm.lock
|
| 66 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 67 |
+
# in version control.
|
| 68 |
+
# https://pdm.fming.dev/#use-with-ide
|
| 69 |
+
.pdm.toml
|
| 70 |
+
|
| 71 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 72 |
+
__pypackages__/
|
| 73 |
+
|
| 74 |
+
# Celery stuff
|
| 75 |
+
celerybeat-schedule
|
| 76 |
+
celerybeat.pid
|
| 77 |
+
|
| 78 |
+
# SageMath parsed files
|
| 79 |
+
*.sage.py
|
| 80 |
+
|
| 81 |
+
# Environments
|
| 82 |
+
.env
|
| 83 |
+
.venv
|
| 84 |
+
env/
|
| 85 |
+
venv/
|
| 86 |
+
ENV/
|
| 87 |
+
env.bak/
|
| 88 |
+
venv.bak/
|
| 89 |
+
|
| 90 |
+
# Spyder project settings
|
| 91 |
+
.spyderproject
|
| 92 |
+
.spyproject
|
| 93 |
+
|
| 94 |
+
# Rope project settings
|
| 95 |
+
.ropeproject
|
| 96 |
+
|
| 97 |
+
# mkdocs documentation
|
| 98 |
+
/site
|
| 99 |
+
|
| 100 |
+
# mypy
|
| 101 |
+
.mypy_cache/
|
| 102 |
+
.dmypy.json
|
| 103 |
+
dmypy.json
|
| 104 |
+
|
| 105 |
+
# Pyre type checker
|
| 106 |
+
.pyre/
|
| 107 |
+
|
| 108 |
+
# pytype static type analyzer
|
| 109 |
+
.pytype/
|
| 110 |
+
|
| 111 |
+
# Cython debug symbols
|
| 112 |
+
cython_debug/
|
| 113 |
+
|
| 114 |
+
# PyCharm
|
| 115 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 116 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 117 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 118 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 119 |
+
#.idea/
|
| 120 |
+
|
| 121 |
+
# VS Code
|
| 122 |
+
.vscode/
|
| 123 |
+
|
| 124 |
+
# pycache
|
| 125 |
+
__pycache__/
|
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
import numpy as np
|
| 4 |
+
from sklearn.cluster import MeanShift, estimate_bandwidth
|
| 5 |
+
from sklearn.datasets import make_blobs
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def get_clusters_plot(n_blobs, cluster_std):
|
| 9 |
+
X, _, centers = make_blobs(
|
| 10 |
+
n_samples=10000, cluster_std=cluster_std, centers=n_blobs, return_centers=True
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
bandwidth = estimate_bandwidth(X, quantile=0.2, n_samples=500)
|
| 14 |
+
|
| 15 |
+
ms = MeanShift(bandwidth=bandwidth, bin_seeding=True)
|
| 16 |
+
ms.fit(X)
|
| 17 |
+
labels = ms.labels_
|
| 18 |
+
cluster_centers = ms.cluster_centers_
|
| 19 |
+
|
| 20 |
+
labels_unique = np.unique(labels)
|
| 21 |
+
n_clusters_ = len(labels_unique)
|
| 22 |
+
|
| 23 |
+
colors = ["#dede00", "#377eb8", "#f781bf"]
|
| 24 |
+
markers = ["x", "o", "^"]
|
| 25 |
+
|
| 26 |
+
fig = plt.figure()
|
| 27 |
+
|
| 28 |
+
for k, col in zip(range(n_clusters_), colors):
|
| 29 |
+
my_members = labels == k
|
| 30 |
+
cluster_center = cluster_centers[k]
|
| 31 |
+
plt.plot(X[my_members, 0], X[my_members, 1], markers[k], color=col)
|
| 32 |
+
plt.plot(
|
| 33 |
+
cluster_center[0],
|
| 34 |
+
cluster_center[1],
|
| 35 |
+
markers[k],
|
| 36 |
+
markerfacecolor=col,
|
| 37 |
+
markeredgecolor="k",
|
| 38 |
+
markersize=14,
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
return fig
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
demo = gr.Interface(
|
| 45 |
+
get_clusters_plot,
|
| 46 |
+
[
|
| 47 |
+
gr.Slider(
|
| 48 |
+
minimum=2, maximum=10, label="Number of clusters in data", step=1, value=3
|
| 49 |
+
),
|
| 50 |
+
gr.Slider(
|
| 51 |
+
minimum=0.1,
|
| 52 |
+
maximum=1,
|
| 53 |
+
label="Cluster standard deviation",
|
| 54 |
+
step=0.1,
|
| 55 |
+
value=0.6,
|
| 56 |
+
),
|
| 57 |
+
],
|
| 58 |
+
gr.Plot(),
|
| 59 |
+
allow_flagging="never",
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
if __name__ == "__main__":
|
| 63 |
+
demo.launch()
|