{"id":13710559,"url":"https://github.com/nicodv/kmodes","last_synced_at":"2025-05-14T11:09:41.137Z","repository":{"id":9828570,"uuid":"11815672","full_name":"nicodv/kmodes","owner":"nicodv","description":"Python implementations of the k-modes and k-prototypes clustering algorithms, for clustering categorical data","archived":false,"fork":false,"pushed_at":"2024-06-19T19:59:13.000Z","size":490,"stargazers_count":1257,"open_issues_count":17,"forks_count":414,"subscribers_count":51,"default_branch":"master","last_synced_at":"2025-04-09T03:09:53.661Z","etag":null,"topics":["clustering-algorithm","k-modes","k-prototypes","python","scikit-learn"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nicodv.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-08-01T11:54:40.000Z","updated_at":"2025-04-01T08:40:39.000Z","dependencies_parsed_at":"2024-06-18T12:23:33.337Z","dependency_job_id":"c5de457a-dc0c-4278-9985-d52a53630e0d","html_url":"https://github.com/nicodv/kmodes","commit_stats":{"total_commits":479,"total_committers":22,"mean_commits":"21.772727272727273","dds":0.3757828810020877,"last_synced_commit":"61265b159e8a33af779fba005912a5185fd82078"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicodv%2Fkmodes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicodv%2Fkmodes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicodv%2Fkmodes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicodv%2Fkmodes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nicodv","download_url":"https://codeload.github.com/nicodv/kmodes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254129489,"owners_count":22019628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["clustering-algorithm","k-modes","k-prototypes","python","scikit-learn"],"created_at":"2024-08-02T23:00:58.235Z","updated_at":"2025-05-14T11:09:41.087Z","avatar_url":"https://github.com/nicodv.png","language":"Python","readme":".. image:: https://img.shields.io/pypi/v/kmodes.svg\n    :target: https://pypi.python.org/pypi/kmodes/\n    :alt: Version\n.. image:: https://anaconda.org/conda-forge/kmodes/badges/version.svg\n    :target: https://anaconda.org/conda-forge/kmodes\n    :alt: Conda forge page\n.. image:: https://github.com/nicodv/kmodes/actions/workflows/python-package.yml/badge.svg?branch=master\n    :target: https://github.com/nicodv/kmodes/actions/workflows/python-package.yml\n    :alt: Build status\n.. image:: https://coveralls.io/repos/nicodv/kmodes/badge.svg\n    :target: https://coveralls.io/r/nicodv/kmodes\n    :alt: Test coverage\n.. image:: https://api.codacy.com/project/badge/Grade/cb19f1f1093a44fa845ebfdaf76975f6\n   :alt: Codacy\n   :target: https://app.codacy.com/app/nicodv/kmodes?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=nicodv/kmodes\u0026utm_campaign=Badge_Grade_Dashboard\n.. image:: https://img.shields.io/pypi/dm/kmodes.svg\n    :target: https://pypi.python.org/pypi/kmodes/\n    :alt: Monthly downloads\n.. image:: https://img.shields.io/pypi/pyversions/kmodes.svg\n    :target: https://pypi.python.org/pypi/kmodes/\n    :alt: Supported Python versions\n.. image:: https://img.shields.io/pypi/l/kmodes.svg\n    :target: https://github.com/nicodv/kmodes/blob/master/LICENSE\n    :alt: License\n\nkmodes\n======\n\nDescription\n-----------\n\nPython implementations of the k-modes and k-prototypes clustering\nalgorithms. Relies on numpy for a lot of the heavy lifting.\n\nk-modes is used for clustering categorical variables. It defines clusters\nbased on the number of matching categories between data points. (This is\nin contrast to the more well-known k-means algorithm, which clusters\nnumerical data based on Euclidean distance.) The k-prototypes algorithm\ncombines k-modes and k-means and is able to cluster mixed numerical /\ncategorical data.\n\nImplemented are:\n\n- k-modes [HUANG97]_ [HUANG98]_\n- k-modes with initialization based on density [CAO09]_\n- k-prototypes [HUANG97]_\n\nThe code is modeled after the clustering algorithms in :code:`scikit-learn`\nand has the same familiar interface.\n\nI would love to have more people play around with this and give me\nfeedback on my implementation. If you come across any issues in running or\ninstalling kmodes,\n`please submit a bug report \u003chttps://github.com/nicodv/kmodes/issues\u003e`_.\n\nEnjoy!\n\nInstallation\n------------\n\n`kmodes` can be installed using `pip`:\n\n.. code:: bash\n\n    pip install kmodes\n\nTo upgrade to the latest version (recommended), run it like this:\n\n.. code:: bash\n\n    pip install --upgrade kmodes\n\n`kmodes` can also conveniently be installed with `conda` from the `conda-forge` channel:\n\n.. code:: bash\n\n    conda install -c conda-forge kmodes\n\nAlternatively, you can build the latest development version from source:\n\n.. code:: bash\n\n    git clone https://github.com/nicodv/kmodes.git\n    cd kmodes\n    python setup.py install\n\nUsage\n-----\n.. code:: python\n\n    import numpy as np\n    from kmodes.kmodes import KModes\n\n    # random categorical data\n    data = np.random.choice(20, (100, 10))\n\n    km = KModes(n_clusters=4, init='Huang', n_init=5, verbose=1)\n\n    clusters = km.fit_predict(data)\n\n    # Print the cluster centroids\n    print(km.cluster_centroids_)\n\nThe examples directory showcases simple use cases of both k-modes\n('soybean.py') and k-prototypes ('stocks.py').\n\nParallel execution\n------------------\n\nThe k-modes and k-prototypes implementations both offer support for\nmultiprocessing via the \n`joblib library \u003chttps://pythonhosted.org/joblib/generated/joblib.Parallel.html\u003e`_,\nsimilar to e.g. scikit-learn's implementation of k-means, using the\n:code:`n_jobs` parameter. It generally does not make sense to set more jobs\nthan there are processor cores available on your system.\n\nThis potentially speeds up any execution with more than one initialization try,\n:code:`n_init \u003e 1`, which may be helpful to reduce the execution time for\nlarger problems. Note that it depends on your problem whether multiprocessing\nactually helps, so be sure to try that out first. You can check out the\nexamples for some benchmarks.\n\nFAQ\n---\n\n**Q: I'm seeing errors such as \"TypeError: '\u003c' not supported between instances of 'str' and 'float'\"\nwhen using the kprototypes algorithm.**\n\nA: One or more of your numerical feature columns have string values in them. Make sure that all \ncolumns have consistent data types.\n\n----\n\n**Q: How does k-protypes know which of my features are numerical and which are categorical?**\n\nA: You tell it which column indices are categorical using the :code:`categorical` argument. All others are assumed numerical. E.g., :code:`clusters = KPrototypes().fit_predict(X, categorical=[1, 2])`\n\n----\n\n**Q: I'm getting the following error, what gives? \"ModuleNotFoundError: No module named 'kmodes.kmodes'; 'kmodes' is not a package\".**\n\nA: Make sure your working file is not called 'kmodes.py', because it might overrule the :code:`kmodes` package.\n\n----\n\n**Q: I'm getting the following error: \"ValueError: Clustering algorithm could not initialize. Consider assigning the initial clusters manually.\"**\n\nA: This is a feature, not a bug. :code:`kmodes` is telling you that it can't make sense of the data you are presenting it. At least, not with the parameters you are setting the algorithm with. It is up to you, the data scientist, to figure out why. Some hints to possible solutions:\n\n- Run with fewer clusters as the data might not support a large number of clusters\n- Explore and visualize your data, checking for weird distributions, outliers, etc.\n- Clean and normalize the data\n- Increase the ratio of rows to columns\n\n----\n\n**Q: I'm getting the following error: \"ValueError: Input contains NaN, infinity, or a value too large for dtype('float64').\"**\n\nA: Following scikit-learn, the k-modes algorithm does not accept :code:`np.NaN` \nvalues in the :code:`X` matrix. Users are suggested to fill in the missing \ndata in a way that makes sense for the problem at hand.\n\n----\n\n**Q: How would like your library to be cited?**\n\nA: Something along these lines would do nicely:\n\n.. code-block::\n\n  @Misc{devos2015,\n    author = {Nelis J. de Vos},\n    title = {kmodes categorical clustering library},\n    howpublished = {\\url{https://github.com/nicodv/kmodes}},\n    year = {2015--2024}\n  }\n\n\nReferences\n----------\n\n.. [HUANG97] Huang, Z.: Clustering large data sets with mixed numeric and\n   categorical values, Proceedings of the First Pacific Asia Knowledge\n   Discovery and Data Mining Conference, Singapore, pp. 21-34, 1997.\n\n.. [HUANG98] Huang, Z.: Extensions to the k-modes algorithm for clustering\n   large data sets with categorical values, Data Mining and Knowledge\n   Discovery 2(3), pp. 283-304, 1998.\n\n.. [CAO09] Cao, F., Liang, J, Bai, L.: A new initialization method for\n   categorical data clustering, Expert Systems with Applications 36(7),\n   pp. 10223-10228., 2009.\n","funding_links":[],"categories":["其他_机器学习与深度学习","Machine Learning Framework","Python","Feature Extraction"],"sub_categories":["Nearest Neighbors \u0026 Similarity","General Feature Extraction"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicodv%2Fkmodes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicodv%2Fkmodes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicodv%2Fkmodes/lists"}