Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

find the best k value of K-mean based on Gap statistics

Project Description

this script is using the gap statistics to run k-means algorithm for many times to find the best K value for the dataset.

because k-mean really depends on the initial points and thus the results can be different given different initial points; therefore use sklearn packages to run many times with different initial ponits, and this can be one parameter for the gap statistics.

this module should be imported into other python scripts and combined with sklearn to find the best K value.

parameters:

refs: np.array or None, it is the replicated data that you want to compare with if there exists one; if no existing replicated/proper data, just use None, and the function will automatically generates them;

B: int, the number of replicated samples to run gap-statistics; it is recommended as 10, and it should not be changed/decreased that to a smaller value;

K: list, the range of K values to test on;

N_init: int, states the number of initial starting points for each K-mean running under sklearn, in order to get stable clustering result each time; you may not need such many starting points, so it can be reduced to a smaller number to quicken the computation;

n_jobs: int, clarifies the parallel computing, could fasten the computation, this can be only changed inside the script, not as an argument of the function;

# to install
pip install gapkmean
# to use as a module in python
from gapkmean import gap

# to find the best K value of K-mean algorithm

#note data should be an numpy.array gaps, s_k, K = gap.gap_statistic(data, refs=None, B=10, K=range(1,11), N_init = 10) bestKValue = gap.find_optimal_k(gaps, s_k, K)
Release History

Release History

This version
History Node

1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
gapkmean-1.0.tar.gz (3.4 kB) Copy SHA256 Checksum SHA256 Source Dec 5, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting