轮廓系数大于多少一般认为是很好地聚类系数

  推荐期刊投稿
&&&免费论文
&&&收费论文
&&&浏览历史使用轮廓系数来确定K_其它编程-织梦者
当前位置:&>&&>& > 使用轮廓系数来确定K
使用轮廓系数来确定K
在使用K-means算法的时候,我们最纠结的两个点,第一个点是我们不知道分为几类,第二个点初始的聚类中心对聚类结果的影响,我们在这些使用轮廓系数评判聚类结果的好坏来确定初始的聚类中心和簇的数量。
首先随机生成多个聚类中心,然后分别计算每一个聚类中心的聚类结果的轮廓系数,然后我们我们找到最好的初始聚类中心。我们按照多个类进行聚类,分别计算轮廓系数,然后找到最优的聚类结果。
package com.winning.dm.
import java.util.ArrayL
public class Kmeans {
// 一维数据集合
public ArrayList&Double&
// 聚类的数量
// 计算当前的聚类中心
public double[]
// 存储上一次的聚类中心
public double[]
// 聚类中心最好改变最小的阈值
// 聚类结果每一个ArrayList是一个聚类结果
public ArrayList&ArrayList&Double&&
// 进行随机生成五次的聚类中心
public ArrayList&double[]&
// 记录每次每次聚类计算的s值。
public ArrayList&Double&
public ArrayList&Double& getDataset() {
public void setDataset(ArrayList&Double& dataset) {
this.dataset =
public int getK() {
public void setK(int k) {
public double[] getCenter() {
public void setCenter(double[] center) {
this.center =
public double getMin() {
public void setMin(double min) {
this.min =
public ArrayList&ArrayList&Double&& getSon() {
public void setSon(ArrayList&ArrayList&Double&& son) {
this.son =
* @作者: liusen
下午4:14:49
* @描述: 初始化数据k
* @param k
* @param dataset
* @param min
中心停止迭代的阈值
public Kmeans(int k, ArrayList&Double& dataset, double min) {
this.dataset =
this.min =
this.son = new ArrayList&ArrayList&Double&&();
for (int i = 0; i & this.k; i++) {
ArrayList&Double& al = new ArrayList&Double&();
this.son.add(al);
* @作者: liusen
下午4:16:01
* @描述: 随机生成聚类中心
public void createCenter() {
double[] hs = new double[this.k];
for (int i = 0; i & this.k; i++) {
double a = this.dataset.get((int) Math.random()
* (this.dataset.size()));
for (int j = 0; j & j++) {
if (a == hs[j]) {
// System.out.println(hs[0] + "-----" + hs[1]);
this.setCenter(hs);
* @作者: liusen
下午4:16:29
* @描述: 根据距离聚类中心的距离对数据进行分组
public void groupby() {
for (Double db : dataset) {
double[] dl = new double[this.k];
for (int i = 0; i & this.k; i++) {
dl[i] = this.distance(db, this.center[i]);
int m = this.findMinDistance(dl);
// 对数据进行分组
this.son.get(m).add(db);
* @作者: liusen
下午4:17:48
* @描述:计算两个数据之间的距离
* @param a
* @param b
public double distance(double a, double b) {
return Math.abs(a - b);
* @作者: liusen
下午4:18:55
* @描述: 找到聚类中心
* @param db
public int findMinDistance(double[] db) {
int result = 0;
double min = db[0];
for (int i = 0; i & this.k; i++) {
if (db[i] & min) {
* @作者: liusen
下午4:20:57
* @描述: 更新聚类中心位置
public double[] iteration() {
double[] result = new double[this.son.size()];
for (int i = 0; i & this.son.size(); i++) {
result[i] = this.mean(this.son.get(i));
* @作者: liusen
下午4:21:56
* @描述: 计算每一个簇的中心位置
* @param s
public double mean(ArrayList&Double& s) {
double result = 0;
for (Double d : s) {
return result / s.size();
* @作者: liusen
下午4:22:22
* @描述: 使用迭代找到聚类的中心
public ArrayList&ArrayList&Double&& cluster() {
// 根据中心进行分组以便于迭代出下一个组中心
this.groupby();
// 根据分组的数据求出新的聚类中心
this.nowcenter = this.iteration();
// 进行判断分析迭代是否终止,只有所有的中心的差都满足条件的时候才终止迭代
for (int i = 0; i & this.center. i++) {
if (Math.abs(this.center[i] - this.nowcenter[i]) & this.min) {
this.center = this.
// 每次迭代重新赋值一下分类好的集合
// this.son = new ArrayList&ArrayList&Double&&();
// 对重新分好类的集合进行重新赋值
// for (int m = 0; m & this.k; i++) {
// ArrayList&Double& al = new ArrayList&Double&();
// this.son.add(al);
for (int m = 0; m & this.k; i++) {
this.son.get(m).clear();
// 重新进行迭代
this.cluster();
return this.
* @作者: liusen
下午5:50:53
* @描述: 进行多次随机生成中心,然后选取最好的
public ArrayList&ArrayList&Double&& mangTimeGroup() {
this.ssum = new ArrayList&Double&();
this.mangtimecenter = new ArrayList&double[]&();
for (int i = 0; i & 5; i++) {
// 创造一个随机的中心
this.createCenter();
// 对中心进行迭代
Online ol = new Online(this.cluster());
// 计算每一次分组的轮廓系数
this.ssum.add(ol.counts());
this.mangtimecenter.add(this.center);
double min = this.ssum.get(0);
int upp = 0;
for (int i = 1; i & this.ssum.size(); i++) {
if (this.ssum.get(i) & min) {
min = this.ssum.get(i);
this.setCenter(this.mangtimecenter.get(upp));
return this.cluster();
以上是K-means聚类算法。
下面是轮廓系数的计算过程。
package com.winning.dm.
import java.util.ArrayL
public class Online {
public ArrayList&ArrayList&Double&&
public ArrayList&ArrayList&Double&&
public ArrayList&ArrayList&Double&&
public ArrayList&ArrayList&Double&&
* @作者: liusen
下午3:54:00
* @描述: 把分类好的数据data导入类中
* @param data
分好类的数据
public Online(ArrayList&ArrayList&Double&& data) {
this.data =
* @作者: liusen
下午3:55:12
* @描述: 计算簇间平均距离
* @param i
表示数据在哪一个簇中
* @param j
表示数据在簇中的位置
* @param al
数据所在的簇
public void counta(int i, int j, ArrayList&Double& al) {
this.aal.get(i)
this.countDistance(this.data.get(i).get(j), al)
/ al.size() - 1);
* @作者: liusen
下午3:55:59
* @描述: 计算簇外平均距离
* @param i
数据所在的簇
* @param j
数据在簇中的位置
public void countb(int i, int j) {
double[] d = new double[this.data.size()];
for (int m = 0; m & this.data.size(); i++) {
if (m != i) {
d[m] = this.countDistance(this.data.get(m).get(j),
this.data.get(m))
/ this.data.get(m).size();
Sort.Sort(d);
this.bal.get(i).set(j, d[1]);
* @作者: liusen
下午4:07:30
* @描述: 计算数据跟簇之间的距离和
* @param d
* @param al
public double countDistance(double d, ArrayList&Double& al) {
double sum = 0;
for (Double db : al) {
sum += Math.abs(db - d);
* @作者: liusen
下午4:08:12
* @描述: 计算出数据的轮廓系数
public double counts() {
//初始化aal数据
this.aal=new ArrayList&ArrayList&Double&&();
for(int i=0;i&this.data.size();i++){
ArrayList&Double& al=new ArrayList&Double&();
this.aal.add(al);
//初始化bal
this.bal=new ArrayList&ArrayList&Double&&();
for(int i=0;i&this.data.size();i++){
ArrayList&Double& al=new ArrayList&Double&();
this.bal.add(al);
//分别计算每一个簇的簇内距离
for (int i = 0; i & this.data.size(); i++) {
for (int j = 0; j & this.data.get(i).size(); j++) {
this.counta(i, j, this.data.get(i));
this.countb(i, j);
this.sal.get(i).add(
(this.bal.get(i).get(j) - this.aal.get(i).get(j))
/ Math.max(this.bal.get(i).get(j), this.aal
.get(i).get(j)));
double sum = 0;
double result = 0;
for (int i = 0; i & this.sal.size(); i++) {
for (int j = 0; j & this.sal.get(i).size(); j++) {
sum += this.sal.get(i).get(j);
return sum /
以上就是使用轮廓系数来确定K的全文介绍,希望对您学习和使用程序编程有所帮助.
这些内容可能对你也有帮助
更多可查看其它编程列表页。
猜您也会喜欢这些文章 上传我的文档
 下载
 收藏
桥梁工程专业工程师,硕士学历,擅长桥梁设计,结构有限元分析,岩土分析计算。
 下载此文档
基于轮廓系数的层次聚类算法研究多
下载积分:1250
内容提示:基于轮廓系数的层次聚类算法研究多
文档格式:PDF|
浏览次数:78|
上传日期: 05:21:13|
文档星级:
全文阅读已结束,如果下载本文需要使用
 1250 积分
下载此文档
该用户还上传了这些文档
基于轮廓系数的层次聚类算法研究多
官方公共微信你似乎来到了没有知识存在的荒原...
来源链接是否正确?用户、话题或问题是否存在?FastCGI Error
FastCGI Error
The FastCGI Handler was unable to process the request.
Error Details:
The FastCGI process has failed frequently recently. Try the request again in a while
Error Number: - (0x).
Error Description: ???,?¨u??í?ó
HTTP Error 500 - Server Error.Internet Information Services (IIS)

我要回帖

更多关于 聚类系数 的文章

 

随机推荐