Compare commits

...

3 Commits

Author SHA1 Message Date
lorenzo30salgado
c503f046e8
Merge 24666d3cd7 into f3f32ae3ca 2024-11-21 21:27:41 +05:30
pre-commit-ci[bot]
f3f32ae3ca
[pre-commit.ci] pre-commit autoupdate (#12385)
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.7.3 → v0.7.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.3...v0.7.4)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-11-18 22:07:12 +01:00
lorenzo30salgado
24666d3cd7
Adding a 3D plot to the k-means clustering algorithm 2024-11-12 10:59:24 +01:00
2 changed files with 22 additions and 2 deletions

View File

@ -16,7 +16,7 @@ repos:
- id: auto-walrus
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.3
rev: v0.7.4
hooks:
- id: ruff
- id: ruff-format

View File

@ -37,7 +37,13 @@ Usage:
heterogeneity,
k
)
5. Transfers Dataframe into excel format it must have feature called
5. 3D Plot of the labeled data points with centroids.
plot_kmeans(
X,
centroids,
cluster_assignment
)
6. Transfers Dataframe into excel format it must have feature called
'Clust' with k means clustering numbers in it.
"""
@ -126,6 +132,19 @@ def plot_heterogeneity(heterogeneity, k):
plt.show()
def plot_kmeans(data, centroids, cluster_assignment):
ax = plt.axes(projection="3d")
ax.scatter(data[:, 0], data[:, 1], data[:, 2], c=cluster_assignment, cmap="viridis")
ax.scatter(
centroids[:, 0], centroids[:, 1], centroids[:, 2], c="red", s=100, marker="x"
)
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
ax.set_title("3D K-Means Clustering Visualization")
plt.show()
def kmeans(
data, k, initial_centroids, maxiter=500, record_heterogeneity=None, verbose=False
):
@ -193,6 +212,7 @@ if False: # change to true to run this test case.
verbose=True,
)
plot_heterogeneity(heterogeneity, k)
plot_kmeans(dataset["data"], centroids, cluster_assignment)
def report_generator(