资源简介
数据文件已经项目目录下,直接在IDE导入项目运行即可。(注:该项目是在jdk1.8环境下编译)
数据文件已经项目目录下,直接在IDE导入项目运行即可。(注:该项目是在jdk1.8环境下编译)

代码片段和文件信息
package com.hokilin.kmeans;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Random;
public class KAverage {
private int sampleCount = 0;
private int dimensionCount = 0;
private int centerCount = 0;
private double[][] sampleValues;
private double[][] centers;
private double[][] tmpCenters;
private String dataFile = ““;
/**
* 通过构造器传入数据文件
*/
public KAverage(String dataFile) throws NumberInvalieException {
this.dataFile = dataFile;
}
/**
* 第一行为s;d;c含义分别为样例的数目,每个样例特征的维数,聚类中心个数 文件格式为d[d]...;d[d]... 如:12;23;15
* 每一维之间用隔开,每个样例间用;隔开。结尾没有‘;‘ 可以有多行
*/
private int initData(String fileName) {
String line;
String samplesValue[];
String dimensionsValue[] = new String[dimensionCount];
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(fileName));
} catch (FileNotFoundException e) {
e.printStackTrace();
return -1;
}
/*
* 预处理样本,允许后面几维为0时,不写入文件
*/
for (int i = 0; i < sampleCount; i++) {
for (int j = 0; j < dimensionCount; j++) {
sampleValues[i][j] = 0;
}
}
int i = 0;
double tmpValue = 0.0;
try {
line = in.readLine();
String params[] = line.split(“;“);
if (params.length != 3) {// 必须为3个参数,否则错误
in.close();
return -1;
}
/**
* 获取参数
*/
this.sampleCount = Integer.parseInt(params[0]);
this.dimensionCount = Integer.parseInt(params[1]);
this.centerCount = Integer.parseInt(params[2]);
if (sampleCount <= 0 || dimensionCount <= 0 || centerCount <= 0) {
in.close();
throw new NumberInvalieException(“input number <= 0.“);
}
if (sampleCount < centerCount) {
in.close();
throw new NumberInvalieException(
“sample number < center number“);
}
sampleValues = new double[sampleCount][dimensionCount + 1];
centers = new double[centerCount][dimensionCount];
tmpCenters = new double[centerCount][dimensionCount];
while ((line = in.readLine()) != null) {
samplesValue = line.split(“;“);
for (int j = 0; j < samplesValue.length; j++) {
dimensionsValue = samplesValue[j].split(““);
for (int k = 0; k < dimensionsValue.length; k++) {
tmpValue = Double.parseDouble(dimensions
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-05-24 13:43 Kmeans\
文件 302 2017-05-24 13:43 Kmeans\.classpath
文件 382 2017-05-24 13:43 Kmeans\.project
目录 0 2017-05-24 13:43 Kmeans\.settings\
文件 598 2017-05-24 13:43 Kmeans\.settings\org.eclipse.jdt.core.prefs
目录 0 2017-05-24 21:19 Kmeans\bin\
目录 0 2017-05-24 13:43 Kmeans\bin\com\
目录 0 2017-05-24 13:43 Kmeans\bin\com\hokilin\
目录 0 2017-05-24 13:43 Kmeans\bin\com\hokilin\kmeans\
文件 6294 2017-05-24 13:46 Kmeans\bin\com\hokilin\kmeans\KAverage.class
文件 902 2017-05-24 13:43 Kmeans\bin\com\hokilin\kmeans\NumberInvalieException.class
文件 85 2017-05-24 13:45 Kmeans\bin\sample.txt
文件 89 2017-05-24 20:58 Kmeans\bin\使用说明.txt
目录 0 2017-05-24 21:19 Kmeans\src\
目录 0 2017-05-24 13:43 Kmeans\src\com\
目录 0 2017-05-24 13:43 Kmeans\src\com\hokilin\
目录 0 2017-05-24 13:43 Kmeans\src\com\hokilin\kmeans\
文件 9036 2017-05-24 13:46 Kmeans\src\com\hokilin\kmeans\KAverage.java
文件 603 2017-05-20 11:03 Kmeans\src\com\hokilin\kmeans\NumberInvalieException.java
文件 85 2017-05-24 13:45 Kmeans\src\sample.txt
文件 89 2017-05-24 20:58 Kmeans\src\使用说明.txt
- 上一篇:Java 字符/字母 雨
- 下一篇:J2EE期末复习题汇总
相关资源
- 《程序员代码面试指南 》左神 高清
- 简易C语言编译器Java源代码
- 酒店管理系统JAVA源代码245552
- 飞机大战/雷霆战机 全部Java源代码,
- 图书馆管理系统java源代码
- 超市收银系统java源代码264295
- 仓库管理系统+JAVA源代码++设计说明
- Weka同步课本-Data_Mining
- java源代码 人事管理系统
- 超市管理系统——Java源代码
- java电子邮件收发系统 java源代码
- 空当接龙java源代码
- Clique聚类算法Java版
- java源代码,java源代码
- 仓库管理系统JAVA源代码
- 学生信息管理系统含Java源代码 毕业论
- 5款新闻发布系统JSP+JAVA源代码
- 网上商城java源代码
- 航空售票管理信息系统内含数据库文
- 自己开发的消灭星星android-java源代码
- 上位机源代码java源代码
- weka3.4.13
- KTV点歌系统(JAVA+MYSQL)
- java项目实-科研信息发布平台.zip
- 当当网网上书店java源代码
- 物流信息管理系统 java源代码
- 飞机大战java源代码
- java电子邮件收发系统 java源代码2.2版
- 人事管理系统java源代码和数据库SQL
- 一个家庭记账的java源代码
评论
共有 条评论