Coder Social home page Coder Social logo

k-means's Introduction

K-Means算法的Python实现

注:该数据集仅为Demo,如需完整数据请Email:[email protected]

如果觉得对您有帮助的话,劳烦给个Star

在K-Means.py中定义了一个KMeans类,只需要两行代码即可实现K-Means中心聚类算法

km = KMeans(dataset_tmp, 3)  # 聚成三个簇
km.fit()

该类具体方法如下:

__init__(self, dataset, cluster_num=2)

该类的初始化方法,参数如下:

dataset: list 数据集,列表嵌套列表的形式。例如[[1,2,3,...], [4,5,6,...],...]

cluster_num: int 要划分的簇的个数。Default: 2

return: None

Demo: 若要对dataset_tmp进行聚类,首先实例化KMeans类

附部分dataset_tmp截图

{% qnimg K-Means算法及Python实现_dataset_demo.png alt:dataset_demo %}

km = KMeans(dataset_tmp, 3)

fit(self)

进行聚类

return: None

km.fit()

_distance(p1, p2)

p1点和p2点的欧氏距离

@staticmethod

p1: list 形如[x,y]

return: None

_center(_list):

计算坐标组中的中心点

@staticmethod

_list: list 形如dataset,列表嵌套列表的形式。例如[[1,2,3,...], [4,5,6,...],...]

return: list 中心点坐标[x,y,z,...]

k-means's People

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

pointerhu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.