{"id":21850596,"url":"https://github.com/freakwill/semi-kmeans","last_synced_at":"2026-05-13T07:31:02.489Z","repository":{"id":255952647,"uuid":"853965488","full_name":"Freakwill/semi-kmeans","owner":"Freakwill","description":"Semi supervised k-means algo.","archived":false,"fork":false,"pushed_at":"2024-09-08T03:08:53.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-21T17:55:47.936Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Freakwill.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-08T03:06:47.000Z","updated_at":"2024-09-08T03:08:56.000Z","dependencies_parsed_at":"2024-09-08T04:22:59.449Z","dependency_job_id":null,"html_url":"https://github.com/Freakwill/semi-kmeans","commit_stats":null,"previous_names":["freakwill/semi-kmeans"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Freakwill/semi-kmeans","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freakwill%2Fsemi-kmeans","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freakwill%2Fsemi-kmeans/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freakwill%2Fsemi-kmeans/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freakwill%2Fsemi-kmeans/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Freakwill","download_url":"https://codeload.github.com/Freakwill/semi-kmeans/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freakwill%2Fsemi-kmeans/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32972705,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T06:31:55.726Z","status":"ssl_error","status_checked_at":"2026-05-13T06:31:51.336Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-28T00:18:28.530Z","updated_at":"2026-05-13T07:31:02.463Z","avatar_url":"https://github.com/Freakwill.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# semi-kmeans\nSemi supervised k-means algo.\n\n\n```python\n#!/usr/bin/env python\n\nimport numpy as np\nfrom sklearn.model_selection import train_test_split\nfrom semi_kmeans import *\nfrom sklearn.cluster import KMeans\n\nfrom sklearn import datasets\ndigits = datasets.load_digits()\nX, y = digits.data, digits.target\n\nfrom sklearn.decomposition import PCA\npca = PCA(n_components=2)\nX = pca.fit_transform(X)\n\nn_clusters = 4\nX = X[y\u003cn_clusters]; y = y[y\u003cn_clusters]\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)\nX_labeled, X_unlabeled, y_labeled, _ = train_test_split(X_train, y_train, test_size=0.95)\n\n# create semi k-means\nskm = SemiKMeans(n_clusters=n_clusters)\nskm.fit(X_labeled, y_labeled, X_unlabeled)\n\nkm = KMeans(n_clusters=n_clusters)\nkm.fit(X)\nclf = SupervisedKMeans()\nclf.fit(X_labeled, y_labeled)\n\n# print(f\"\"\"\n# # clusters: 10\n# # samples: {X_labeled.shape[0]} + {X_unlabeled.shape[0]}\n# SemiKMeans: {km.score(X_test, y_test)}\n# SupervisedKMeans: {skm.score(X_test, y_test)}\n# \"\"\")\n\nfrom utils import visualize\n\nimport matplotlib.pyplot as plt\nplt.style.use('b_style.mplstyle')\n\nfig = plt.figure(constrained_layout=True)\nax = fig.add_subplot(111)\n\nx1lim = X[:, 0].min(), X[:, 0].max()\nx2lim = X[:, 1].min(), X[:, 1].max()\n\nax.scatter(*X_unlabeled.T, color='grey', alpha=0.4)\nvisualize(ax, skm, X_labeled, y_labeled, x1lim=x1lim, x2lim=x2lim, N1=400, N2=400, boundary=True, boundary_kw={'s':1.6, 'alpha': 0.8, 'c':'red'})\nvisualize(ax, clf, X_labeled, y_labeled, x1lim=x1lim, x2lim=x2lim, N1=50, N2=40, scatter=False, boundary_kw={'s':1.6, 'alpha': 0.5, 'c':'blue'})\nvisualize(ax, km, X, y, N1=60, N2=50, scatter=False, boundary=False, background=True, background_kw={'alpha': 0.05, 'marker': 's'})\nax.set_xlabel('$x_1$')\nax.set_ylabel('$x_2$')\nax.plot([0],[0], 'r-', label=f'semi-K-means cluster（test：{skm.score(X_test, y_test):.4}）', alpha=0.7)\nax.plot([0],[0], 'b:', label=f'K-means classifer（test：{clf.score(X_test, y_test):.4}）', alpha=0.4)\nax.legend()\nplt.savefig('../src/semi-kmeans.png')\nplt.show()\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreakwill%2Fsemi-kmeans","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreakwill%2Fsemi-kmeans","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreakwill%2Fsemi-kmeans/lists"}